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

书上的源代码如下

watchlist.html

<head>
<meta charset="utf-8">
<title>{{ user.username }}'s Watchlist</title>
</head>
<body>
<a href="{{ url_for('index') }}">&larr; 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”错误的更多相关文章

  1. Nagios Apache报Internal Server Error错误的解决方法

    今天配置Nagios的时候遇到了一些麻烦,前面的步骤都一切顺利,nagios运行后,可以看到nagios的主页,但点击左边的菜单时总是提示Internal Server Error错误.错误如下: v ...

  2. nginx提示:500 Internal Server Error错误的解决方法

    现在越来越多的站点开始用 Nginx ,("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 ...

  3. 【转】nginx提示:500 Internal Server Error错误的解决方法

    本文转自:http://www.jb51.net/article/35675.htm 现在越来越多的站点开始用 Nginx ,("engine x") 是一个高性能的 HTTP 和 ...

  4. php 图片上传 500 Internal Server Error 错误

    写php简单上传图片时,发现200k的图片上传时报Internal Server Error错误,检查了upload_max_filesize,及其他post_max_size.max_input_t ...

  5. Nginx频繁报“500 Internal Server Error”错误

    服务器导致访问量激增,频繁报"500 Internal Server Error"错误.我查了一下nginx的错误日志(apt-get方式安装的nginx的错误日志在/var/lo ...

  6. <<< php程序在运行后报“internal server error”错误

    上传的php程序在运行后报“internal server error”错误,检查以下两方面: 1.请您检查php程序的属性是否设置为755,如果php程序的属性不是755,那么运行的时候会报“int ...

  7. 创建keystone的catalog时提示:‘Internal Server Error (HTTP 500)’

    在生成keystone的catalog时: [root@controller ~]# openstack service create --name keystone --description &q ...

  8. Nginx出现500 Internal Server Error 错误的解决方案

    500(服务器内部错误) 服务器遇到错误,无法完成请求. 501(尚未实施) 服务器不具备完成请求的功能.例如,当服务器无法识别请求方法时,服务器可能会返回此代码. 502(错误网关) 服务器作为网关 ...

  9. HTTP 错误 500.19 - Internal Server Error 错误解决

    今天在测试部署站点是遇到一个问题 HTTP 错误 500.19 - Internal Server Error  如下图,在网上搜了写解决方法,什么设置iis目录浏览,删除web.config中配置, ...

随机推荐

  1. imageio.ffmpeg.download() has been deprecated. Use 'pip install im ageio-ffmpeg' instead.'

    Use this instead: sudo pip3 install imageio==2.4.1

  2. python分割txt文件

    a=open('A.txt','r').readlines() n=3 #份数 qty=len(a)//n if len(a)%n==0 else len(a)//n+1 #每一份的行数 for i ...

  3. linux 安装 ImageMagick 和 imagick 扩展

    使用命令安装 1.依次运行以下命令 yum install ImageMagick yum install ImageMagick-devel yum install php-pear 安装php-p ...

  4. Vue中的事件与常见的问题处理

    Vue的事件:获取事件对象$event: 事件冒泡:事件会向上传播 原生js阻止事件冒泡,需要先获取事件对象,再调用stopPropagation()方法: vue事件修饰符stop,例@clik.s ...

  5. Python3 WebDriver操作cookie的方法

    Python3 WebDriver操作cookie的方法 WebDriver提供了操作Cookie的相关方法,可以读取.添加和删除cookie信息. WebDriver操作cookie的方法: get ...

  6. python之块包导入

    一.模块 1.什么是模块 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写 ...

  7. hdu 4366 Successor - CDQ分治 - 线段树 - 树分块

    Sean owns a company and he is the BOSS.The other Staff has one Superior.every staff has a loyalty an ...

  8. Python 基础指令

    ## Python 基础指令 ```Shell $ pip install ipython== # 安装指定版本的python第三方库 $ python --version #查看版本 $ which ...

  9. SpringCloud与Consul集成实现负载均衡

    一.背景 SpringCloud微服务目前比较流行,其中大都在使用的服务注册与发现是Eureka,最近研究了Consul的集群搭建,现使用Consul实现服务的负载均衡.其主要拓扑结构如下: 二.Co ...

  10. 【转载】RabbitMQ基础知识

    本文转自: https://www.cnblogs.com/dwlsxj/p/RabbitMQ.html 一.背景 RabbitMQ是一个由erlang开发的AMQP(Advanced Message ...