render_template and the templates Folder
Return an HTML file instead of a string.
From Strings to Pages
So far your routes returned plain strings. Real pages need HTML, and Flask gives you render_template to serve full HTML files cleanly.
What render_template Does
render_template finds an HTML file, runs it through the template engine, and returns the finished page as your response body.
from flask import render_template
@app.route('/')
def home():
return render_template('index.html')All lessons in this course
- render_template and the templates Folder
- Pass Data into a Template
- Jinja2 Loops and Conditionals
- Autoescaping and the safe Filter