Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *