Answer the question
In order to leave comments, you need to log in
How to dynamically assign one of several values to a WTForms descendant field when initializing a class instance?
Good time.
# Project on Flask + WTForms
I have several custom SelectFields and a form in which one and the same field, depending on the conditions, must be assigned one or another SelectField.
# in view
@app.route('/some/<int:a>/', methods=['POST', 'GET'])
def f(a):
form = MyForm(a=a)
return render_template('t.html', form=form)
# in forms
class MyForm(Form):
next = HiddenField()
static_field1 = StringField()
static_field2 = StringField()
static_field3 = StringField()
# здесь проблема
# если a == 1 то необходимо сделать specific_field = CustomSelect1(),
# но если a == 2, то specific_field = CustomSelect()2
specific_field = ?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question