第一次学习Flask,我正在尝试按照教程构建内容。当我输入这个网址时,我在浏览器中收到此消息:
http://127.0.0.1:5000/index
127.0.0.1 - - [16/Jun/2014 19:37:41] "GET /index HTTP/1.1" 500 -
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
我不确定为什么会收到此错误。有人能帮帮我,告诉我为什么吗?我是Flask和Web开发的新手
代码:
from flask import Flask, request, make_response, redirect, render_template
from flask.ext.script import Manager
from flask.ext.bootstrap import Bootstrap
app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/user/<name>')
def user(name):
return render_template('user.html', name = name)
if __name__ == '__main__':
#app.run(debug = True)
manager.run()
的index.html:
{% extends "base.html" %}
{% block title %} Index {% block title %}
{% block head %}
<!-- Uses super() to retain the original contents-->
{{ super() }}
<style type="text/css">
</style>
{% endblock %}
{% block body %}
<h1>Hello, World!</h1>
{% endblock %}
这是我的项目结构:
/Flask_0_11
/templates
base.html
index.html
user.html
hello.py
答案 0 :(得分:8)
index.html
中存在模板语法错误。
标题栏应以{% endblock %}
:
{% block title %} Index {% endblock %}
您可以打开DEBUG
配置进行调试。因为您使用Flask-Script
,所以可以将-d
选项传递给runserver命令。
e.g。
python hello.py runserver -d
答案 1 :(得分:3)
首先尝试使用
运行应用程序python manage.py runserver -d
这将以调试模式运行您的烧瓶应用程序,显示您的应用程序中遇到的错误,可以轻松进行更正。
其次,由于配置文件中没有WTF_CSRF_ENABLED = True和SECRET_KEY,可能会出现错误。