第一次学习Flask,我正在尝试按照教程来构建一些东西。当我输入以下url时,我在浏览器中收到以下消息:
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发布于 2014-06-17 11:09:04
您的index.html中存在模板语法错误。
标题栏应使用{% endblock %}关闭
{% block title %} Index {% endblock %}您可以打开DEBUG配置以进行调试。因为您使用的是Flask-Script,所以可以将-d选项传递给runserver命令。
例如:
python hello.py runserver -d发布于 2016-03-27 13:26:34
首先,尝试使用以下命令运行该应用程序
python manage.py runserver -d这将在调试模式下运行您的flask应用程序,显示在您的应用程序中遇到的错误,轻松进行更正。
其次,由于配置文件中的SECRET_KEY没有WTF_CSRF_ENABLED = True,可能会出现错误。
https://stackoverflow.com/questions/24254945
复制相似问题