烧瓶用python dict中的值填写表格

时间:2018-09-08 16:21:37

标签: python flask flask-wtforms

我希望烧瓶形式预先填充python dict中的数据

form_input()函数获取python dict'ext'并返回表单。

我遇到的错误是“ jinja2.exceptions.UndefinedError:'str对象'没有属性'发出者'”

@app.route('/form_input', methods=["GET", "POST"])
def form_input():

ext = session['ext']
if request.method == 'POST':
    form  = Dataentryform(request.form, obj=ext)    


return render_template("inputdata.html",form='form')

Ext是Python字典-

([('amount', 200.22), ('currency', 'USD'), ('date', datetime.datetime(2017, 7, 30, 0, 0)), ('desc', 'Invoice from KOTH Commercial Broker'), ('invoice_number', ('DTBINT', '0907')), ('issuer', 'KOTH Commercial Broker'), ('partner_name', 'KOTH Commercial Broker')])

这里是input.html

{% from "_formhelpers.html" import render_field %}
<form method=post>
<dl>
    {{ render_field(form.issuer) }}
    {{ render_field(form.invoice_number) }}
    {{ render_field(form.date) }}
    {{ render_field(form.currency) }}
    {{ render_field(form.amount) }}
</dl>
<p><input type=submit value=Submit>

1 个答案:

答案 0 :(得分:0)

form应该是变量,而不是字符串。

所以改变

return render_template("inputdata.html",form='form')

return render_template("inputdata.html",form=form)