Skip to content

Templates setup

Manish Sah edited this page Sep 17, 2020 · 1 revision

Setup templates

so far, we have been returning only the string values when user visits some url.

We can return an actual html page instead of just some string.

  • create a directory named templates in our blog package(name should be templates)
  • add home.html file in that directory

we can return html files from our routes in the following way

from blog import app
from flask import render_template

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

flask has method called render_template which can return html file instead of plain string.

render_templates always look for the html files in our templates directory. This is reason why we name our directory as templates

Implementation can be found over this commit

Clone this wiki locally