E
E
Enter_a_nickname2022-03-04 12:20:38
Django
Enter_a_nickname, 2022-03-04 12:20:38

2 save buttons on one page. How to name these functions and use them?

How to create 2 forms on one page for filling in data and implement separate functions for saving to the database?
On the Internet, I read about naming save functions and found this example:

<form method='POST'>
    {{form1.as_p}}
    <button type="submit" name="btnform1">Save Changes</button>
    </form>
    <form method='POST'>
    {{form2.as_p}}
    <button type="submit" name="btnform2">Save Changes</button>
    </form>


if request.method=='POST' and 'btnform1' in request.POST:
    do something...
if request.method=='POST' and 'btnform2' in request.POST:
    do something...


I don’t understand how to write a function in views correctly, help with a small example, I will be very grateful

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question