Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask basics... url
#1
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]

Attached Files

.html   movie.html (Size: 336 bytes / Downloads: 226)
Reply
#2
return redirect(url_for('...'))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask Basics request.form ifigazsi 0 1,804 Feb-09-2021, 09:05 AM
Last Post: ifigazsi
  what to learn after the basics? mitmit293 1 2,030 Feb-06-2019, 11:59 PM
Last Post: metulburr
  MechanicalSoup Basics Datiswaken 3 4,236 Mar-07-2018, 04:13 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020