记录flask使用模板时出现的“Internal Server Error”错误
在看《Flask Web开发实战:入门、进阶与原理解析(李辉著 )》时照着书上的代码抄了一遍,然后运行时发现一直出现以下的错误

书上的源代码如下
watchlist.html
<head>
<meta charset="utf-8">
<title>{{ user.username }}'s Watchlist</title>
</head>
<body>
<a href="{{ url_for('index') }}">← Return</a>
<h2>{{ user.username }}</h2>
{% if user.bio %}
<i>{{ user.bio }}</i>
{% else %}
<i>This user has not provided a bio.</i>
{% endif %}
{# Below is the movie list (this is comment) #}
{<h5>{{ user.username }}'s Watchlist({{ movies|length }}):</h5>
<ul>
{% for movie in movies %}
<li>{{ movie.name }} - {{ movie.year }}</li>
{% endfor %}
</ul>
</body>
</html>
app.py
user = {
'username': 'Grey Li',
'bio': 'A boy who loves movies and music.',
}
movies = [
{'name': 'My Neighbor Totoro', 'year': ''},
{'name': 'Three Colours trilogy', 'year': ''},
{'name': 'Forrest Gump', 'year': ''},
{'name': 'Perfect Blue', 'year': ''},
{'name': 'The Matrix', 'year': ''},
{'name': 'Memento', 'year': ''},
{'name': 'The Bucket list', 'year': ''},
{'name': 'Black Swan', 'year': ''},
{'name': 'Gone Girl', 'year': ''},
{'name': 'CoCo', 'year': ''},
]
from flask import Flask,render_template,url_for
app = Flask(__name__)
@app.route('/watchlist')
def watchlist():
return render_template('watchlist.html', user=user, movies=movies)
@app.route('/')
def index():
return render_template('index.html')
'''
if __name__=='__main__':
app.run()
'''
控制台还输入了“werkzeug.routing.BuildError: Could not build url for endpoint 'index.html'. Did you mean 'index' instead?”的错误提示,看不懂
在谷歌有很多类似这样的错误提示的解决办法,但都不是我要找的。刚开始以为是在app.py中没有加上32、33行。
后来才发现应该是在watchlist中加上了 <!-- 注释--> 的内容,大概有几行吧,然后删去注释,重新 flask run 再在浏览器中打开就可以了。
所以有个疑惑,在模板中的貌似不能像在html中那样使用 <!-- 注释-->的格式了。
说明:代码源于《Flask Web开发实战:入门、进阶与原理解析(李辉著 )》一书
我个人觉得这本书挺好的,讲得详细易懂。
记录flask使用模板时出现的“Internal Server Error”错误的更多相关文章
- Nagios Apache报Internal Server Error错误的解决方法
今天配置Nagios的时候遇到了一些麻烦,前面的步骤都一切顺利,nagios运行后,可以看到nagios的主页,但点击左边的菜单时总是提示Internal Server Error错误.错误如下: v ...
- nginx提示:500 Internal Server Error错误的解决方法
现在越来越多的站点开始用 Nginx ,("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 ...
- 【转】nginx提示:500 Internal Server Error错误的解决方法
本文转自:http://www.jb51.net/article/35675.htm 现在越来越多的站点开始用 Nginx ,("engine x") 是一个高性能的 HTTP 和 ...
- php 图片上传 500 Internal Server Error 错误
写php简单上传图片时,发现200k的图片上传时报Internal Server Error错误,检查了upload_max_filesize,及其他post_max_size.max_input_t ...
- Nginx频繁报“500 Internal Server Error”错误
服务器导致访问量激增,频繁报"500 Internal Server Error"错误.我查了一下nginx的错误日志(apt-get方式安装的nginx的错误日志在/var/lo ...
- <<< php程序在运行后报“internal server error”错误
上传的php程序在运行后报“internal server error”错误,检查以下两方面: 1.请您检查php程序的属性是否设置为755,如果php程序的属性不是755,那么运行的时候会报“int ...
- 创建keystone的catalog时提示:‘Internal Server Error (HTTP 500)’
在生成keystone的catalog时: [root@controller ~]# openstack service create --name keystone --description &q ...
- Nginx出现500 Internal Server Error 错误的解决方案
500(服务器内部错误) 服务器遇到错误,无法完成请求. 501(尚未实施) 服务器不具备完成请求的功能.例如,当服务器无法识别请求方法时,服务器可能会返回此代码. 502(错误网关) 服务器作为网关 ...
- HTTP 错误 500.19 - Internal Server Error 错误解决
今天在测试部署站点是遇到一个问题 HTTP 错误 500.19 - Internal Server Error 如下图,在网上搜了写解决方法,什么设置iis目录浏览,删除web.config中配置, ...
随机推荐
- pat 团体赛练习题集 L2-008. 最长对称子串
对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...
- self asyncio
import asyncio from threading import Thread import time print('main start:',time.time()) async def d ...
- 20145320《WEB基础实践》
20145320WEB基础实践 实验问题回答 1.什么是表单 表单可以收集用户的信息和反馈意见,是网站管理者与浏览者之间沟通的桥梁. 一个表单有三个基本组成部分: 表单标签 表单域:包含了文本框.密码 ...
- Codeforces Round #479 (Div. 3)题解
CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...
- 定制FileField中的上传文件名称
FileField中的upload_to属性可以设定上传文件的存储目录和名称,它可以是个字符串,也可以是个callable,比如一个方法. 当upload_to的值设为一个方法时,就可以对上传文件的名 ...
- topcoder srm 455 div1
problem1 link 令$f[x1][y1][x2][y2]$表示矩形(x1,y1)(x2,y2)中能选出的最大值.dp即可. problem2 link 这个题应该有更好的递推公式. 我的做法 ...
- Bootstrap3基础 clearfix pull-left/right 辅助类样式 快速左右浮动
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- Python3 tkinter基础 Canvas create_polygon 画三角形
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- ng-model绑定的是ng-option中的什么?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- strerror函数的总结【转】
本文转载自:https://www.cnblogs.com/xrcun/p/3210889.html 定义函数:char * strerror(int errnum); 函数说明:strerror() ...