存在时无法找到 index.html(Flask Python)
Cannot find index.html when it exists (Flask Python)
在创建服务器的接近尾声时,我创建了一个主页并将其附加到 python 文件,但是当我尝试从我的 phone 访问主页时,在日志中返回这个:
jinja2.exceptions.TemplateNotFound: /index.html
- - [25/Dec/2021 20:27:57] "GET / HTTP/1.1" 500 -
index.html 存在,这是一个神秘的行为,需要建议。
address.py:
api = Flask(__name__)
@api.route('/')
def index():
return render_template('/index.html')
index.html
应该在名为 templates
的目录中
您也可以在 render_template
:
的参数中不使用正斜杠
return render_template('index.html')
在创建服务器的接近尾声时,我创建了一个主页并将其附加到 python 文件,但是当我尝试从我的 phone 访问主页时,在日志中返回这个:
jinja2.exceptions.TemplateNotFound: /index.html - - [25/Dec/2021 20:27:57] "GET / HTTP/1.1" 500 -
index.html 存在,这是一个神秘的行为,需要建议。
address.py:
api = Flask(__name__)
@api.route('/')
def index():
return render_template('/index.html')
index.html
应该在名为 templates
您也可以在 render_template
:
return render_template('index.html')