我試圖用Flask-Bootstrap quick_form
呈現WTF表單。但是,我得到一個錯誤,即form
未定義,即使我將其傳入render_template
。爲什麼這不起作用?Flask-Bootstrap quick_form認爲從render_template傳入的表單未定義
File "/home/eron/anaconda/lib/python2.7/site-packages/flask_bootstrap/templates/bootstrap/wtf.html", line 190, in template
{{ form.hidden_tag() }}
File "/home/eron/anaconda/lib/python2.7/site-packages/jinja2/environment.py", line 397, in getattr
return getattr(obj, attribute)
UndefinedError: 'form' is undefined
from flask.ext.wtf import Form
class NameForm(Form):
name = StringField('Login', validators=[Required()])
submit = SubmitField('Submit')
@app.route('/base', methods=['GET','POST'])
def index():
name = None
form = NameForm()
if form.validate_on_submit():
name = form.name.data
session['name'] = form.name.data
return redirect(url_for('base'))
return render_template('base.html', form=form)
{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
<div class="col-md-3">
{{ wtf.quick_form(form) }}
</div>
什麼背後的邏輯是什麼?那將意味着我會通過課堂而不是對象本身,不是嗎? – elelias