'str' 尝试预填充表单时无法调用对象

'str' object is not callable when trying to prefill form

我正在尝试实现一种用于更新用户先前发布的信息的表单。不幸的是,我收到一个 TypeError: 'str' object is not callable.

我在网上寻找解决方案,但找不到任何解决方案 - 我猜这个错误与我试图预填 Select 字段的值有关,但我可能是错了。

views.py

@users.route('/<int:query_id>/update', methods=['GET', 'POST'])
@login_required
def update_query(query_id):
   query = Model.query.get_or_404(query_id)

   if query.author != current_user:
    abort(403)

   form = QueryForm()

   if form.validate_on_submit():
       query.property_type = form.property_type.data
       query.property_type_details = form.property_type_details.data

       db.session.commit()

       return redirect(url_for('users.user_profile', username=current_user.username))

   elif request.method == 'GET':
       form.property_type = query.property_type
       form.property_type_details = query.property_type_details

   return render_template('users/update-query.html', form=form)

forms.py

class QueryForm(FlaskForm):
   submit = SubmitField('Send')

   property_type = SelectField(u'Type', choices=[('House', 'House'), ('Apartment', 'Apartment')])
   property_type_details = SelectField(u'Detail', choices=[('Something', 'Something'),('SomethingElse', 'SomethingElse')])

模板

<form method='POST' class="query-form" action="" enctype="multipart/form-data">
      {{form.hidden_tag()}}

       <h4 class="text-center">Info</h4>

          <div class="form-row">
             <div class="form-group col-md-4">
                {{form.property_type.label}}
                {{form.property_type(class="form-control")}} 
              </div>

              <div class="form-group col-md-4">
                {{form.property_type_details.label}}
                {{form.property_type_details(class="form-control")}}
              </div>
          </div>
</form>

最近的调用和错误

File "/Users/1/Desktop/Code/Project/Name/main/templates/users/update-query.html", line 33, in block "content"
{{form.property_type_details(class="form-control")}}

TypeError: 'str' object is not callable

预填两个表单字段意味着为两个字段实例设置 data 属性。 1

目前,这两个字段的实例都被从数据库中检索到的值覆盖。

如下更新时预填充两个字段的块解决了在模板中呈现预填充两个字段的错误。

elif request.method == 'GET':
       form.property_type.data = query.property_type
       form.property_type_details.data = query.property_type_details