A route decorator connects a Flask URL address to the Python view function that handles it. Writing @app.route('/hello/<name>') lets the browser reach greet through addresses such as /hello/Emily. section 10.0
A route decorator can:
- Capture information from a dynamic URL, such as the name in /hello/<name>. section 10.0
- Accept selected request methods, as in /order with GET and POST. section 10.0
- Connect an HTML form’s action address to code that reads submitted form data. section 10.0
Greeting and drink order routes
Use @app.route('/hello/<name>') above greet(name) for personalized pages. Use @app.route('/order', methods=('GET', 'POST')) above order() to display a form, read request.form['drink'] after submission, and render the result. section 10.0
@app.route('/hello/<name>')
def greet(name='Stranger'):
return render_template("greeting.html", name=name)
Inspect the compact route-and-function example showing a dynamic URL value passed into a rendered template. section 10.0
