liveBook · Manning

Render_template

As explained in A Pythonic Adventure: From Python basics to a working web app

render_template is a Flask function that loads a template, combines it with supplied values, and returns rendered content.

render_template() connects Flask code to a page template: pass a template filename and values, and the rendered content appears in the browser. section 10.0

A submitted order follows a small, friendly relay:

  • Read the selected drink with request.form['drink']. section 10.0
  • Return print.html while passing drink=drink. section 10.0
  • Display the value with {{drink}} inside the template. section 10.0

Show the customer’s drink

Inside the order route, return render_template("print.html", drink=drink). In print.html, place {{drink}} where the selected drink should appear. section 10.0

@app.route('/order', methods=('GET', 'POST'))
def order():
    if request.method == 'POST':
        drink = request.form['drink']
        print("Drink: ", drink)
        return render_template("print.html", drink=drink)   #1
 
    return render_template("forms.html")

Browse the complete order route, including GET and POST handling and the value passed to print.html. section 10.0

How A Pythonic Adventure: From Python basics to a working web app covers it

How deep it goes
Explains filename and keyword-value passing through a worked order flow, stopping short of deeper template internals.
Examples
Uses a drink-order form, print.html, {{drink}}, and a New Order button.
What it assumes
Assumes basic Python and HTML forms while demonstrating route handling and template values incrementally.
What you can do after
Apply via Flask by rendering a template and passing submitted form data into it.
How it connects
Ties Flask routes to request.form, HTML forms, and templates.

Also explained in

Compare how 3 books explain render_template →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of A Pythonic Adventure: From Python basics to a working web app. The section links point to the parts of the book it draws on.