内部服务器错误Flask

Lio*_*cer 6 python flask python-2.7

第一次学习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.
Run Code Online (Sandbox Code Playgroud)

我不知道为什么我会收到这个错误.有人能帮帮我,告诉我为什么吗?我是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()
Run Code Online (Sandbox Code Playgroud)

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 %}
Run Code Online (Sandbox Code Playgroud)

这是我的项目结构:

/Flask_0_11
   /templates
      base.html
      index.html
      user.html
   hello.py
Run Code Online (Sandbox Code Playgroud)

Leo*_*o.Z 8

您的模板语法错误index.html.

标题栏应该关闭{% endblock %}:

{% block title %} Index {% endblock %}
Run Code Online (Sandbox Code Playgroud)

您可以打开DEBUG配置进行调试.因为您使用Flask-Script,您可以将-d选项传递给runserver命令.

例如

python hello.py runserver -d
Run Code Online (Sandbox Code Playgroud)


小智 5

首先尝试使用运行应用程序

python manage.py runserver -d
Run Code Online (Sandbox Code Playgroud)

这将以调试模式运行您的 Flask 应用程序,显示应用程序中遇到的错误,从而轻松进行纠正。

其次,由于配置文件中的 SECRET_KEY 没有 WTF_CSRF_ENABLED = True ,可能会出现错误。