开发者

Process muliple forms in Django view

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜