flask-wtforms

How can I create repetitive form elements in a DRY way with Flask-WTForms?

怎甘沉沦 提交于 2020-08-25 04:56:06
问题 I have a WTForms form where I want the user to be able to upload up to 10 images, and also give the images captions and credits. Currently I declare all 10 sets of fields, but this seems redundant. Is there a way to create form fields with dynamic names, so I could create them in a loop? class MyForm(Form): image1 = FileField('Upload') image1_caption = StringField('Caption') image1_credit = StringField('Credit') image2 = FileField('Upload') image2_caption = StringField('Caption') image2

flask-wtforms. QuerySelectField RuntimeError

本小妞迷上赌 提交于 2020-07-23 06:38:21
问题 Im trying to use QuerySelectField in FlaskForm, but getting error. admin/forms.py class ServiceForm(FlaskForm): # def __init__(self, *args, **kwargs): # super(ServiceForm, self).__init__(*args, **kwargs) # self.category.choices = [(cat.id, cat.name) for cat in ServiceCategory.query.all()] category = QuerySelectField('Category', query_factory=ServiceCategory.query, get_pk=lambda a: a.id, get_label=lambda a: a.name) name = StringField('Name', validators=[DataRequired()]) description =

flask-wtforms. QuerySelectField RuntimeError

送分小仙女□ 提交于 2020-07-23 06:37:49
问题 Im trying to use QuerySelectField in FlaskForm, but getting error. admin/forms.py class ServiceForm(FlaskForm): # def __init__(self, *args, **kwargs): # super(ServiceForm, self).__init__(*args, **kwargs) # self.category.choices = [(cat.id, cat.name) for cat in ServiceCategory.query.all()] category = QuerySelectField('Category', query_factory=ServiceCategory.query, get_pk=lambda a: a.id, get_label=lambda a: a.name) name = StringField('Name', validators=[DataRequired()]) description =