'Render template can not find file [closed]
Hello i am new to Flask and render_template can not find my file
from re import template
from flask import Flask,render_template, request
from datetime import datetime
app = Flask(__name__, template_folder="templates")
now = datetime.now()
date_time= now.strftime("%d/%m/%Y, %H:%M:%S")
@app.route('/')
def hello_world():
# content = "<p> The time is now" + date_time + "</p>"
content = render_template("templates/index.html")
return content
if __name__ == "__main__":
app.run()
this is my code and my folder structure is
flask
|-- pycache
|-- app.py
|-- templates
|--index.html
Solution 1:[1]
Good question. Template paths exclude the "templates/" directory prefix.
Just change render_template("templates/index.html") to render_template("index.html")
from re import template
from flask import Flask,render_template, request
from datetime import datetime
app = Flask(__name__, template_folder="templates")
now = datetime.now()
date_time= now.strftime("%d/%m/%Y, %H:%M:%S")
@app.route('/')
def hello_world():
# content = "<p> The time is now" + date_time + "</p>"
content = render_template("index.html")
return content
if __name__ == "__main__":
app.run()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jake |
