我想创建使用烧瓶它在Web形式的网站,但我不断收到内部服务器错误,尽管没有得到任何错误,当我在控制台运行内部服务器错误
这里是我的代码:
__init.py
from flask import Flask, render_template
from forms import TestForm
app = Flask(__name__)
app.config.from_pyfile('config.py')
@app.route('/')
def homepage():
return render_template("main.html", form=TestForm())
if __name__ == "__main__":
app.run(debug=True)
forms.py
from flask_wtf import Form
from wtforms import StringField, BooleanField
from wtforms.validators import DataRequired
class TestForm(Form):
test_form = StringField('test_form', validators=[DataRequired()])
config.py
WTF_CSRF_ENABLED = True
SECRET_KEY = '<super-secret>'
main.html中
<DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Page</title>
<meta name="viewport" content="width=device-width"
initial=scale=1/>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='favicon.ico') }}" rel="shortcut icon">
</head>
<h2>Hello, this site is meant to test my fill_web_form.py script</h2>
<br>
<br>
<h1>Test Form</h1>
<form action="/" method="post" name="login">
{{ render_field(form.test_form(size=80) }}<br>
<p><input type="submit" value="Sign In"></p>
</form>
</html>
当我运行flask run
我得到这个
$ flask run
* Serving Flask app "FlaskApp"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
当我尝试访问http://127.0.0.1:5000/
两个Chrome和Firefox我得到一个错误,但我觉得这是一个完全不同的问题。
那么,是内部服务器错误?是否有堆栈跟踪? – Rishav
不,它只是说“服务器遇到内部错误,无法完成您的请求。服务器超载或应用程序出现错误。” –
是的,但你的Python控制台没有任何输出?尝试打开调试模式。 – Rishav