开发者_C百科I have 2 forms in my Django view. How can I do a check to see which one has been submitted?
Thanks
Put a different name
attribute on the submit buttons for each form, then check for that key in request.POST
in your view.
Also don't forget to give each form a separate prefix
attribute when you instantiate them, to avoid any possible field name collisions.
Here are some ideas:
- Use different action URLs for the forms, associated with different views.
- Use different action URLs for the forms, associated with the same view but with using different parameters to the view (using the URLconf)
- Use an
<input type="hidden" />
to differentiate between the forms.
Philip
精彩评论