-1
@app.route("/register", methods=["GET", "POST"])
def register():
    form = Form()
    if form.validate_on_submit():
        pass

    
    return render_template("register.html", form=form)

In the above code first there comes the if statement and then the form is returned. So after returning the render_template("register.html", form=form) how does the if statement still validates the form? whereas after return statement is executed the function should stop running.

davidism
  • 121,510
  • 29
  • 395
  • 339
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 31 '22 at 15:07
  • If you submit the form, you make a new request: usually a POST request, with the new data, and you thus rerun the view. – Willem Van Onsem Jul 31 '22 at 16:04

1 Answers1

0

Make sure you have method "POST" within form-tag in the html.

<form method="POST" action="/register">

    <!-- The internal part of form -->

</form>

To see if POST method works you could

from flask import request

@app.route("/register", methods=["GET", "POST"])
def register():
    form = Form()

    if request.method == "POST":
        print('It is POST')
        if form.validate_on_submit():
             print('Form validated')

    return render_template("register.html", form=form)

Then if you get 'It is POST' and not 'Form validated' as the output, then you would need to check your validators in the file where you defined Register-Form.

Aleksei
  • 77
  • 8