记录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中配置, ...
随机推荐
- php开启xdebug扩展
1.下载Xdebug(先看php下的ext文件夹(C:\xampp\php\ext)下有没有php_xdebug.dll文件,如果有的话,就不用下了.) 到目前为止,Xdebug的最新版本为2.7.0 ...
- ELK学习笔记之简单适用的ES集群监控工具cerebro安装使用
安装指导及使用简介 1. 下载安装包: https://github.com/lmenezes/cerebro/releases/download/v0.7.3/cerebro-0.7.3. ...
- P2221 [HAOI2012]高速公路(线段树)
P2221 [HAOI2012]高速公路 显然答案为 $\dfrac{\sum_{i=l}^r\sum_{j=l}^{r}dis[i][j]}{C_{r-l+1}^2}$ 下面倒是挺好算,组合数瞎搞 ...
- memset与malloc性能测试(转)
前一段跟同事聊项目组已有的一些工具,同事讲里面有太多的malloc与memset,对性能的影响比较大,因此今天就在自己的机器上测试了这两个函数,不多说,上数据.测试环境:2.2GHZ.2G内存mems ...
- 【题解】Luogu P1533 可怜的狗狗
原题传送门 莫队介绍,Splay介绍 离线的题目,莫队是不错的解决方法 先把询问排一下序 剩下就套一个莫队的板子 每来一只狗就把漂亮值插入平衡树 每去掉一只狗就把漂亮值从平衡树中删掉 每次查询查平衡树 ...
- 使用注释来解决关于inline-block元素换行问题
昨天群里有人问个问题:为什么button加了文字后,产生了对齐不一致的问题. 原因在于baseline的对齐问题. 然后就有人推荐了一篇文章:关于Vertical-Align你需要知道的事情 其中里面 ...
- bzoj 2084 Antisymmetry - Manacher
题目传送门 需要高级权限的传送门 题目大意 对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作“反对称”字符串. 问给定长度为$n$的一个01串有多少个子串是反对称的 ...
- UVa Live 3942 Remember the Word - Hash - 动态规划
题目传送门 高速路出口I 高速路出口II 题目大意 给定若干种短串,和文本串$S$,问有多少种方式可以将短串拼成长串. 显然,你需要一个动态规划. 用$f[i]$表示拼出串$S$前$i$个字符的方案数 ...
- Catogory如何添加属性
一,Category结构体 typedef struct category_t { const char *name; //类的名字 classref_t cls; //类 struct method ...
- markdown的流程图实现和代码语法着色
用flowchart为markdown添加流程图 举个例子如下,根据这个例子大家就能看懂我到底是怎么实现的 <!DOCTYPE html> <html> <head> ...