【问题标题】:Cannot find index.html when it exists (Flask Python) [duplicate]存在时找不到index.html(Flask Python)[重复]
【发布时间】:2022-01-25 10:55:44
【问题描述】:

在创建服务器快结束时,我创建了一个主页并将其附加到 python 文件中,但是当我尝试从手机访问主页时,在日志上它返回了这个:

jinja2.exceptions.TemplateNotFound: /index.html - - [25/Dec/2021 20:27:57] “GET / HTTP/1.1” 500 -

index.html 存在,这是一种神秘的行为,需要建议。

地址.py:

api = Flask(__name__)

@api.route('/')
def index():
 return render_template('/index.html')  

【问题讨论】:

    标签: python flask server


    【解决方案1】:

    index.html 应该在名为templates 的目录中

    您也可以在 render_template 的参数中不使用正斜杠:

      return render_template('index.html')  
    

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 1970-01-01
      • 2018-12-11
      • 2020-06-18
      • 2019-11-03
      • 1970-01-01
      • 2017-12-14
      • 2017-08-13
      • 2016-09-04
      相关资源
      最近更新 更多