我正在使用 WTForms 为烧瓶制作表格。这是相应的代码:
class UploadForm(flask.ext.wtf.Form):
def __init__(self,year):
flask.ext.wtf.Form.__init__(self)
self.year=year
subjects = app.config["SUBJECTS"][year]
self.fichier = wtforms.fields.FileField(u'Fichier')
self.subject = wtforms.fields.SelectField(u'Matière', choices=subjects)
self.submit = wtforms.fields.SubmitField(u'Envoyer')
@app.route('/upload/<year>')
def upload(year):
print year
form = UploadForm(year)
return flask.render_template('upload.html', form=form)
这是模板upload.html
:
{% extends "base.html" %}
{% block content %}
<h2>Upload</h2>
<form action="{{ url_for('get', year='1A') }}" method="post"
enctype="multipart/form-data">
{{ form.hidden_tag() }}
{{ form.fichier.label }}
{{ form.fichier }}
{{ form.subject.label }}
{{ form.subject }}
{{ form.submit }}
</form>
{% endblock %}
但是当我运行它时,表单没有显示,而是我有这个:
<UnboundField(FileField, (u'Fichier',), {})> <UnboundField(SelectField, (u'Mati\xe8re',), {'choices': [('MA111', 'MA111'), ('NE111', 'NE111')]})> <UnboundField(SubmitField, (u'Envoyer',), {})>
有人可以帮我解决吗?