How can I build multiple submit buttons django form?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
A Django form can have multiple submit buttons when the same validated form data should trigger different actions. The usual pattern is to give each button a distinct name or value and then inspect request.POST in the view to determine which action the user chose.
Multiple Buttons In The Template
The HTML side is straightforward. Keep one form, but add more than one submit button.
Only the clicked button contributes its name and value pair to the POST body, which makes the server-side routing simple.
Handling The Action In A Function View
The important point is that validation happens once. The button only changes what you do with the already-validated data.
Separate Button Names Also Work
Some developers prefer one unique name per button.
Then the view checks membership directly:
Both approaches are valid. A shared action field with different values often scales a bit better when there are more than two actions.
Class-Based Views
In a class-based view, the idea is the same. Inspect self.request.POST after the form validates.
The pattern does not change just because the view style changes.
Use Cases Beyond Save Versus Publish
Multiple submit buttons are also useful for workflows such as:
- previous versus next in a multi-step wizard
- save versus save-and-add-another in admin-like forms
- approve versus reject with the same underlying form fields
The form structure can stay the same while the view chooses different post-submit behavior.
Keep Validation And Action Logic Separate
It is tempting to let different buttons bypass validation, but that usually creates inconsistent behavior. In most cases, validate the form first and then branch by action. If one action truly needs different required fields, that is often a sign the workflow should be split into different forms or steps.
Common Pitfalls
The most common mistake is forgetting that only the clicked submit button is included in the POST body. Another is branching on button action before checking form.is_valid(), which can lead to inconsistent save logic. Developers also sometimes duplicate entire forms just to support two actions when a single form plus button routing would be cleaner. Finally, if the buttons should produce very different validation rules, forcing them into one form can make the code harder to reason about.
Summary
- Multiple submit buttons in Django are usually handled with different button names or values.
- Inspect
request.POSTafter the form validates to determine which action was chosen. - A shared
actionfield with different values is a clean, scalable pattern. - The same technique works in both function-based and class-based views.
- Keep form validation separate from post-submit branching logic.

