How to redirect to another view/page if the form is invalid

aqpcserver

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',{})
PrOgRaMmEr

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 = form = dumyForm()

 context = {'form':form}
 return render(request,'dummy.html',context)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Redirect output to another form

How do I redirect to another page on form submit?

How to redirect to another HTML page after submitting a form?

How to redirect to another form view in python code - Odoo 8

Contact Form - How to not redirect to another page after submission

How to redirect to another page after form submition using a loading screen

Redirect form data in encrypted form to another domain

ERROR "ERR_INVALID_REDIRECT" to Form Login

How to redirect if form isValid()?

How to redirect on submitting a form?

How to redirect if form is not submitted

How to redirect google form

How to redirect to another page

Redirect to another page after form submit

Redirect GET form with action in another url

submit should not redirect to another page in HTML form

Redirect another page after successful form submission

yet another redirect after form submit

redirect to another page after submitting a form

redirect data form tunnel to another network

A button who submits a form and redirect to another page

Error: Form responses must redirect to another location

How to redirect to another page after click on submit button in form with required inputs

How can I on Submit my Form redirect the Results to another Page in React

how to redirect user to another page and then back, while persisting form input values

How do I redirect to another page when a user successfully submits a form?

How can I have a button redirect to another page, but still be able to do form validation in HTML?

How to redirect in Django with form errors?

How to redirect after form validation?