Esempio

class BaseForm(Form):
    @classmethod
    def append_field(cls, name, field):
        setattr(cls, name, field)
        return cls

ProfileForm = BaseForm
ProfileForm.append_field('email', EmailField('Email', [DataRequired(), Email()]))
read_only(ProfileForm.email)
ProfileForm.append_field('name', StringField('Name', [Optional(), Length(max=64)]))
ProfileForm.append_field('surname', StringField('Surname', [Optional(), Length(max=64)]))
ProfileForm.append_field('submit', SubmitField('Update profile',render_kw={"class": "btn btn-success"}))

Ora รจ possibile utilizzare il nostro ProfileForm.

Sitografia

MyWiki: Flask/self-generated-form (last edited 2016-11-15 10:18:20 by risca)