Two different submit buttons in the same form in Django

I have UpdateView in Django.

I only have a regular submit button. When an object is updated correctly, it is redirected to the list of objects through success_url.

Can I create two different submit buttons: one button that sends and redirects to the object list page (ListView) and another button that sends and redirects to the object details page (DetailView)?

I do not know how to do this in a smart way.

+4
source share
1 answer

, . , , POST. , :

<input type="submit" name="list" value="Submit and go to list">
<input type="submit" name="detail" value="Submit and go to detail">

:

if form.is_valid():
    form.save()
    if 'list' in request.POST:
        return redirect('list_url')
    else:
        return redirect('detail_url')
+9

All Articles