python flask错误 raise TemplateNotFound(template) TemplateNotFound: index.html

解决方案:

1.首先确保你把所有flask需要用到的拓展包都装好了。

$ pip install flask
$ pip install flask-login
$ pip install flask-openid
$ pip install flask-mail
$ pip install flask-sqlalchemy
$ pip install sqlalchemy-migrate
$ pip install flask-whooshalchemy
$ pip install flask-wtf
$ pip install flask-babel
$ pip install guess_language
$ pip install flipflop
$ pip install jinja

把所有安装命令都过一遍,以后有用到的地方就不要重新装了。

2.确保你有templates这个文件夹,确保你的html在这个文件夹下面,如我的index.html需要在templates文件夹下。

3.如果你使用pycharm或者类似的编辑器,注意你创建的文件名字是index还是index.html,如果你的名字是index的html文件,那么你在使用render_template的时候调用的应该是index,而非index.html。总之这个函数调用的时候需要与template下的文件同名。

render_template("index",title='Home',user=user)

以上。

猜你喜欢

转载自blog.csdn.net/lwgkzl/article/details/81110196
今日推荐