gpt4 book ai didi

python - 内部服务器错误 Flask

转载 作者:太空狗 更新时间:2023-10-30 00:36:03 26 4
gpt4 key购买 nike

第一次学习 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

最佳答案

您的 index.html 中存在模板语法错误。

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

{% block title %} Index {% endblock %}

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

例如

python hello.py runserver -d

关于python - 内部服务器错误 Flask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24254945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com