Flask render_template

Issue

New to Flask and have some experience with python, when using render_template it simply does not render the template as well as not giving out any errors.
Code Here:

from flask import Flask, render_template

app = Flask(__name__, template_folder= "/templates")




@app.route("/")
def index():
        #return("Index str")
    return render_template("index.html")


@app.route("/crawler")
def crawler():
    return("WebCrawler str")
    return render_template("crawler.html")

if __name__ == "__main__":
    app.run()
    app.debug = True

HTML here (pretty certain file hierarchy is correct).

<!DOCTYPE html>

<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css')}}">
        <meta charset = "utf-8">
        <title> Index</title>
    <head>
    <body>
        <p> This webserver hosts all webapps and will showcase any unfinished applications.
            </p>

        </body>

</html>

root virtual environment

static for css

templates folder

Solution

The default folder for the HTML files is templates. So create a folder called “templates” where your python file is located. Put any HTML files in that folder

Answered By – Ash Pereira

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published