Reputation: 66
In the event that the form is not valid, how do I redirect the user to another page?
def dothings(request):
form = dumyForm(request.POST or None)
if form.is_valid():
#do 123
else:
# INSTEAD OF REINITIALIZING THE FORM LIKE THIS, I WANT TO REDIRECT TO ANOTHER PAGE
form = form = dumyForm()
return render(request,'dummy.html',{})
Upvotes: 0
Views: 1139
Reputation: 1270
Try to use this :
def dothings(request):
if request.method == 'POST':
form = dumyForm(request.POST or None)
if form.is_valid():
**other_code**
return redirect('redirect_page_view')
else:
return redirect('redirect_page_view')
else:
form = dumyForm()
context = {'form':form}
return render(request,'dummy.html',context)
Upvotes: 2
Reputation:
If you're looking to redirect the user to another page, you can use the following line: return HttpResponseRedirect('page/')
, where 'page' is the URL of your other page.
Upvotes: 0