Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to submit two forms in django

if request.method == 'POST':
    form1 = Form1( request.POST,prefix="form1")
    form2 = Form2( request.POST,prefix="form2")
    
    if form1.is_valid():
       # save them    
       
       # context['form1_message'] = 'Form1 saved'
    else: 
       #save them into context
       context['form1']= form1
    
    if form2.is_valid():
       # save them    
       # context['form2_message'] = 'Form2 saved'
    else: 
       #save them into context
       context['form2']= form2

    if form1.is_valid() and  form2.is_valid(): 
       #that's mean both form is valid and saved successfully 
       return redirect('page')
    else:
        return render('/page', context)


else:
    form1 = Form1(prefix="form1")
    form2 = Form2(prefix="form2")
Comment

PREVIOUS NEXT
Code Example
Python :: convert df.isnull().sum() to dataframe 
Python :: pandas check if column is object type 
Python :: DIVAB 
Python :: stop word python 
Python :: how to replace a string in python 
Python :: How to efficiently determine if a search pattern is part of some target string, in Python? 
Python :: python button tkinter change color 
Python :: get hex code of character python 
Python :: Difference between append() and extend() method in Python 
Python :: how to append substring to string in specific position in python 
Python :: long in python 
Python :: matplotlib save figure without showing 
Python :: pandas removing outliers from dataframe 
Python :: getting tradingview historical data using python 
Python :: regular expression syntax python 
Python :: validationerror django params 
Python :: Python NumPy ndarray flat function Example with 2d array 
Python :: disable sns plot python 
Python :: python minecraft server python gui 
Python :: what is the best ide for python 
Python :: telegram.ext package python 
Python :: k fold CV with xgboost 
Python :: sklearn grid search cross validation show progress 
Python :: python wheel 
Python :: create contract from interface in brownie 
Python :: convert PIL RGB to opencv BRG 
Python :: python list insert vs append 
Python :: scan wifi networke micropython 
Python :: Use the "map" function to find all the odd numbers and the even numbers in the list. Print 0 for odd and 1 for even. in python 
Python :: remove grid in imshow 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =