且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Django 的一个页面上处理多个表单的正确方法

更新时间:2023-11-24 12:08:40

您有几个选择:

  1. 在两个表单的操作中放置不同的 URL.然后你会有两个不同的视图函数来处理这两种不同的表单.

  1. Put different URLs in the action for the two forms. Then you'll have two different view functions to deal with the two different forms.

从 POST 数据中读取提交按钮值.您可以判断点击了哪个提交按钮:如何构建多个提交按钮 django 表单?

Read the submit button values from the POST data. You can tell which submit button was clicked: How can I build multiple submit buttons django form?