I have 2 routes :
@app.route('/activity', methods=["GET"])
def addactivity():
return render_template('activity.html')
In acitvity.html I have a form with some fields and I want to submit this form to another route :
@app.route('/students', methods=["GET"])
def addstudents():
return render_template('students.html')
So when I submit the form in acitvity.html I will be redirected to
/students?field1=value1&field2=value2 etc...
For activity form i am using wtforms with validators: DataRequired() or InputRequired()
The problem is that when i am using form.validate() in addstudents route even if form is validated or not it will redirect me to students.html route.I want in case the form is not validated to display the errors in activity.html.How is that possible?
I am new to flask and maybe my whole code is wrong, but the concept is that if the activity form is validated i will be redirected to the students route, if not errors will be displayed in activity route.. Furthermore i need to submit the the form in students route with the args of the previous form.
if request.method == "POST"inside your definition, then put your form validation there. At the end it should bereturn redirect(url_for('students'))POSTorGET, depending on themethodattribute on theformelement. You might useGETfor things like search forms, which are not going to cause a change on the server side. See developer.mozilla.org/en-US/docs/Web/HTML/Element/form