【发布时间】:2017-10-10 00:07:51
【问题描述】:
我目前正在使用一本名为“Head First: Python (2nd Edition)”的书自学 Python,到目前为止它一直很好,但我目前正处于构建简单 web 应用程序的早期阶段。 webapp 允许输入一个短语和字母,然后输出两者的intersection。由于本书的大部分内容都是以此为基础的,因此我无法跳过此内容继续前进。我一直在寻找错误,但无济于事。
本书提供所有代码:http://python.itcarlow.ie/ed2/ch05/webapp/
文件夹中的文件 vsearch4web.py 是最终版本,所以不要使用它。这是我所在的地方,而不是我的 vsearch4web.py 文件夹:
from flask import Flask, render_template
from vsearch import search4letters
app = Flask(__name__)
@app.route('/')
def hello() -> str:
return 'Hello world from Flask!'
@app.route('/search4')
def do_search() -> str:
return str(search4letters('life, the universe, and everything','eiru,!'))
@app.route('/entry')
def entry_page() -> 'html':
return render_template('entry.html',the_title='Welcome to search4letters on the web!')
app.run()
我已经按照说明设置了文件夹结构:
webapp 文件夹 --> vsearch4web.py 静态文件夹(webapp 的子文件夹)-> hf.css(来自“静态”) 模板文件夹(webapp 的子文件夹)--> base.html、entry.html 和 results.html(来自“模板”)
静态文件夹和模板文件夹中的文件可在本书提供的上述网址中下载。
但是,当我运行 vsearch4web.py 并进入浏览器并输入环回地址 (http://127.0.0.1:5000/entry) 时,我收到“500 内部服务器错误”。
http://127.0.0.1:5000/ 和 http://127.0.0.1:5000/search4 都可以工作。
我已尝试多次重新检查代码,但我不知道我缺少什么。
有人可以帮忙吗?
谢谢。
【问题讨论】:
-
html不是 Python 类型 -
尝试
app.run(debug=True)但猜测它找不到您的模板文件夹,或者entry.html
标签: python python-3.x flask jinja2