0Pricing
Flask Academy · Lesson

render_template and the templates Folder

Return an HTML file instead of a string.

render_template and the templates Folder is a free Flask Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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')

The templates Folder

Flask looks for your HTML in a folder named templates next to your app file. Put index.html there and Flask finds it automatically. 📁

myapp/
  app.py
  templates/
    index.html

Why a Fixed Name

The name templates is a convention, not a guess. Flask knows where to look, so you never write the folder path inside render_template.

Reference Only the Filename

You pass just the filename, not a full path. Flask joins it onto the templates folder for you, keeping your code short and portable.

return render_template('about.html')

Subfolders Inside templates

You can group pages in subfolders and reference them with forward slashes. This keeps a large project tidy as it grows.

return render_template('users/profile.html')

A Minimal Template

A template is ordinary HTML at heart. The simplest one is just a regular page with no special syntax yet.

<!doctype html>
<title>Home</title>
<h1>Welcome</h1>

Templates Get Rendered

Even a plain file is rendered: Flask processes it through Jinja2 first. That step is what lets you add dynamic pieces later.

Returning the Result

render_template returns a string of HTML, which you return from your view. Flask wraps it in a proper response with the right content type.

@app.route('/')
def home():
    return render_template('index.html')

TemplateNotFound Errors

If Flask cannot find the file, you get a TemplateNotFound error. Check the spelling and that the file truly sits inside templates.

Separating Logic and Markup

Templates keep HTML out of your Python. Views handle logic, templates handle presentation, and that split keeps both far easier to read.

Quick Check

Where does Flask expect your HTML files to live by default?

Recap

You learned that render_template serves HTML from the templates folder by filename, so logic stays in Python and markup stays in files. Nice work! 🎉

Frequently asked questions

Is the “render_template and the templates Folder” lesson free?

Yes — the full text of “render_template and the templates Folder” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.

What will I learn in “render_template and the templates Folder”?

Return an HTML file instead of a string. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Flask Academy?

No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “render_template and the templates Folder” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Flask Academy lesson?

Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. render_template and the templates Folder
  2. Pass Data into a Template
  3. Jinja2 Loops and Conditionals
  4. Autoescaping and the safe Filter
← Back to Flask Academy