flask, wtforms_alchemy, 关系, 和烦人的 Unbound field not callable 错误

flask, wtforms_alchemy, relationship, and annoying Unbound field not callable error

我正在使用烧瓶、python、wtforms 和 wtforms_alchemy

为什么我得到 'Unboundfield not callable error'

当行 data = ModelFormField(fields.FormField(TestRelationForm)) 存在时,否则不存在?

from wtforms import fields
from wtforms.ext.sqlalchemy.fields import QuerySelectField

from app import app
from app import db

from app.models import *

ModelForm = model_form_factory(Form)

class TestRelationForm(ModelForm):

    class Meta:
        model = TestRelation

    @classmethod
    def get_session():
        # this method should return sqlalchemy session
        return db.session

class TestForm(ModelForm):
    data = ModelFormField(fields.FormField(TestRelationForm))

    class Meta:
        model = Test

    @classmethod
    def get_session():
        # this method should return sqlalchemy session
        return db.session

在我的处理程序中,我调用了 form = TestForm(),所以表单被实例化了......我将实例化传递给主模板,其中包含以下行:return render_template("main.html", form=form)

此时我什至不关心编辑表单,我只希望测试表单也显示 TestRelationForm 中的字段,就像它打算做的那样..

脸掌。

data = ModelFormField(TestRelationForm)

没有

data = ModelFormField(fields.FormField(TestRelationForm))