Answer the question
In order to leave comments, you need to log in
Flask-wtf how to store a value in a field after submitting it?
there is a simple form (flask-wtf):
class Calck(FlaskForm):
sum = StringField('Сумма (руб.)', validators=[DataRequired()])
statement = RadioField('statement',
choices=[('value_1','Заявление 1'),
('value_2','Заявление 2')],
default='value_1')
submit = SubmitField('Рассчитать')
Answer the question
In order to leave comments, you need to log in
Well, if anyone is interested, besides me, I solved it this way: when creating an instance of the form, an instance of the storage class is created, the attributes of which are written to the values entered in the form fields, and then when sending the form values and redirecting to the same page, the values are taken from the storage ...
class Value_calc():
def __init__(self):
self.sum_data = ''
self.statement_data = 'value_1'
from app.services.forms import Calck, Value_calc
@bp.route('/calc', methods=['GET', 'POST'])
def calc():
form = Calck()
data_form = Value_calc() # экземпляр хранилища значений form
calc_validate(form, data_form)
return render_template('calc.html', form=form)
def calc_validate(form, data_form):
if form.validate_on_submit():
state_fee = form.gscalc_arbitr(form.sum.data, form.statement.data)
flash(state_fee)
data_form.sum_data = form.sum.data
data_form.statement_data = form.statement.data
return redirect(url_for('services.calc'))
else:
form.sum.data = data_form.sum_data
form.statement.data = data_form.statement_data
return form.sum.data, form.statement.data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question