1

im trying to render html template that i download free from a website. every time i run the program it just result error 404 Not Found

[Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.]

and in the vscode it give me

127.0.0.1 - - [11/Jun/2023 14:12:16] "GET / HTTP/1.1" 404 -

result.

my path//

-project
  -templates
    -index.html
  -main.py

this my code

from flask import Flask, render_template


app = Flask(__name__)

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



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

is everyone have a though what should i do so i can run the html template with no errors? thank you for who can answer the question.

rchan
  • 11
  • 3

1 Answers1

0

Try configuring the Flask app.

import os

base_dir = os.path.abspath(os.path.dirname(__file__))    
app = Flask(__name__, template_folder=f'{base_dir}\\project\\templates\\')

and also make the app.route a decorator:

@app.route("/")
def home():
    return render_template("index.html")
Fire
  • 1
  • 3