Im trying to create two buttons on a page. Each one I would like to carry out a different python script on the server. So far I have only managed to get/collect one button using
def contact():
form = ContactForm()
if request.method == 'POST':
return 'Form posted.'
elif request.method == 'GET':
return render_template('contact.html', form=form)
What would I need to change based on button pressed?
Apply (different) name attribute to both buttons like
and catch them in request.data.
I handle it in the following way:
Python Code :
Give your two buttons the same name and different values:
Then in your Flask view function you can tell which button was used to submit the form:
The appropriate way for doing this:
Put
watch
anddownload
buttons into your template.I think this solution is good:
Form:
In case anyone was still looking and came across this SO post like I did.
Simple, concise, and it works. Don't even need to instantiate a form object.