开发者

Process muliple forms in Django view

开发者 https://www.devze.com 2022-12-24 16:52 出处:网络
开发者_C百科I have 2 forms in my Django view. How can I do a check to see which one has been submitted?

开发者_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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号