W
W
weranda2021-07-20 21:09:03
Flask
weranda, 2021-07-20 21:09:03

How to pass form data to another page in Flask in WTForms?

Greetings.

I've been messing around with this for a long time and I can't decide. It is necessary that upon successful completion of the form, the data from it is displayed on another page. For example, the form is on the page /form/, and the data from it should be displayed on the page /form-success/. Suggest a solution.

Now stopped at this. The results of the form are displayed on the same page.

#app.py

...
class MyForm(FlaskForm):
    name = StringField('Ваше имя', [Length(min=3, max=10, message='Укажите имя')])
    submit = SubmitField('Отправить')


@app.route('/form/', methods=['GET', 'POST'])
def render_form():
    form = MyForm()
    if form.validate_on_submit():
        output = render_template('form-success.html', form=form)
        return output
    else:
        output = render_template('form.html', form=form)
        return output
...


#form.html
<form action='/form/' method='POST'>
    {{ form.name.errors[0] }}
    {{ form.name.label }}: {{ form.name }}
    {{ form.hidden_tag() }}
    {{ form.submit }}
</form>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question