Python Forum

Full Version: Flask basics... url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!
When I render the movie.html page, is it possible to change the url as well?

Thank you!

from flask import Flask, render_template, request

app = Flask(__name__)

db_movie = {}
db_movie['Dune'] = {'distributor': 'Werner',
                    'runtime': 155}
db_movie['It'] = {'distributor': 'Werner',
                    'runtime': 135}

#I have 2 pages: /movies/Dune & /movies/It

@app.route('/movies/<movie>', methods=['POST', 'GET'])
def movie_page(movie):
    if request.method == 'POST':
        requested_movie = request.form.get('requested_movie')
        movie = requested_movie #so it loads the data, of the other, but the URL is not changing...

    return render_template('movie.html', title=movie, db_movie=db_movie)


if __name__ == '__main__':
    app.run()
[html]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Movies</title>
</head>
<body>
<h1>{{ title }}</h1>
<h2>{{ db_movie[title]["runtime"] }}</h2>
<form action="" method="post">
<input type="text" name="requested_movie">
<input type="submit">
</form>
</body>
</html>
[/html]
return redirect(url_for('...'))