how to submit two forms in django

Solutions on MaxInterview for how to submit two forms in django by the best coders in the world

showing results for - "how to submit two forms in django"
Eline
11 Aug 2020
1if request.method == 'POST':
2    form1 = Form1( request.POST,prefix="form1")
3    form2 = Form2( request.POST,prefix="form2")
4    
5    if form1.is_valid():
6       # save them    
7       
8       # context['form1_message'] = 'Form1 saved'
9    else: 
10       #save them into context
11       context['form1']= form1
12    
13    if form2.is_valid():
14       # save them    
15       # context['form2_message'] = 'Form2 saved'
16    else: 
17       #save them into context
18       context['form2']= form2
19
20    if form1.is_valid() and  form2.is_valid(): 
21       #that's mean both form is valid and saved successfully 
22       return redirect('page')
23    else:
24        return render('/page', context)
25
26
27else:
28    form1 = Form1(prefix="form1")
29    form2 = Form2(prefix="form2")
30
queries leading to this page
multiple form in one form django createdjango handle two form in one pageseveral submit buttons in form django templatedjango multiple forms on a pageuse one submit button for 2 forms djangotwo forms one page djangohow to render two different forms in the same iew in djangomultiple forms in djangohow to create single form for multiple pages in djangotwo forms in one django viewdjango with 2 submit on form templatedjango form helper add submit to specific form when multiple forms on same pagehow to get two form value in one submit in djangodjango formset add multiple of the same formdjango two total formsdjango multiple formsmultiple forms on one forms in djangohow to use two submit buttons in one form in djangodjango use two formhow to render two different forms in the same view in django but submit differentlymultiple form in djangomultiple form handeling djangodjango form two buttons in one form only one should workdjango form two submit buttonssubmit two form with same button djangomultiple data send in django formstwo forms in post djangomultiple forms on one page djangoform 3d two forms djangoformset from two form djangohow to deal with several forms on one page in djangomultiple form djangosubmit multiple forms djangobutton submit multiple fields in djangosubmit multiple forms at once in djangohow to add multiple forms in djangouse two django form on the same pageworking with multiple html forms djangotwo formsets one form djangodjango multiple forms one submitone submit button for multiple forms djangodjango multiple forms on one pagehow to understand which form is submitted if i have multiple forms in a page djangotwo forms on one page djangosubmit two forms with one view djangodjango total forms two2 forms in one html page djangosubmitting multiple forms as one djangouse two forms in one view django formsmultiple form data djangodjango two forms on one pageformset with multiple forms djangohandling multiple forms in djangohow to submit two different forms to two different models djangodjango two forms one submitadding multiple forms to a django pagehow to submit two forms in django