用Flask写,到了往前端页面 render_template()数据这一步,突然开始作死式的报错,怎么调后端都没用;哪位大神帮忙找出原因,谢谢
报错:
前端模板:“index.html”
{% extends "base.html" %}
{% extends "bootstrap/wtf.html" as wtf %}
{% block title %} Hello {% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Hello,{% if name %}{{ name }}{% else %}Stranger{% endif %}!</h1>
</div>
{{ wtf.quick_form(form) }}
{% endblock %}
后端文件:"Hello.py"
from flask import Flask
from flask import render_template
from flask_bootstrap import Bootstrap
from flask_moment import Moment
# from datetime import datetime
# from flask import abort
from flask_script import Manager
from flask_wtf import Form
from wtforms import StringField,SubmitField
from wtforms.validators import DataRequired
app = Flask(__name__)
app.config["SECRET_KEY"] = "hard to guess string" #设置Flask-WTF
manager = Manager(app)
bootstrap = Bootstrap(app) #初始化Flask-Boorstrap
moment = Moment(app) #初始化Flask-Moment
#定义表单类
class NameForm(Form):
name = StringField("What is your name?",validators=[DataRequired()])
submit = SubmitField("Submit")
@app.errorhandler(404)
def page_not_found(e):
return render_template("404.html"),404
@app.errorhandler(500)
def internal_server_error(e):
return render_template("500.html"),500
@app.route('/',methods = ["GET","POST"])
def index():
name = None
form = NameForm()
if form.validate_on_submit():
name = form.name.data
form.name.data = ""
return render_template("index.html")
if __name__ == '__main__':
# app.run(host = "0.0.0.0")
app.run(debug = True)
把
{% extends "bootstrap/wtf.html" as wtf %}
改成:参考《Flask Web开发实战》第四章