I am new to Python and Flask. I am trying to use WTForm FlaskForm, and having problems with choices in SelectField. I am building my forms like this.
class FightForm(FlaskForm):
fight_id = StringField('fight_id', render_kw={'readonly': True})
fight_type_id = SelectField('fight_type_id',
choices=[(t.fight_type_id, t.type_name) for t in fight_type.query.all()], validate_choice=False, validators=[DataRequired()])
These choices appear to only load 1 time. If I go add a new fight_type
, I have to stop the application and restart if for it to refresh.
Also, I found this answer, flask wtforms selectfield choices not update, but FlaskForm does not trigger the __init__
function this suggests.
I changed it temporarily to Form anyway and got an error saying fight_type_id does not belong to form (paraphrasing).
I would like for these to refresh every time I call the page.
source https://stackoverflow.com/questions/71258629/flaskform-had-to-reload-select-choices
Comments
Post a Comment