Menu Close

How to build multiple submit buttons in a Python Django form?

To build multiple submit buttons in a Python Django form, we can render the buttons conditionally.

For instance, we write

if 'newsletter_sub' in request.POST:
    # do subscribe
elif 'newsletter_unsub' in request.POST:
    # do unsubscribe

to render one submit button if the newletter_sub key is in request.POST.

And we render another submit button if the newsletter_unsub key is in request.POST.

Posted in Python, Python Answers