Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6350053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:44:18+00:00 2026-05-24T21:44:18+00:00

Hi Stackoverflow people, I am irritated by the the Django Form handling, if the

  • 0

Hi Stackoverflow people,

I am irritated by the the Django Form handling, if the form submits to new page and the form validation fails. I intended to return to the earlier submitted form, and display the error message for correction.

The error message will be displayed, but the url link is not changing.
How can I change the *else statement of the is_valid() statement*, in order to redirect to the earlier form?

Thank you for your advice!

urls.py

urlpatterns = patterns("",
    url(r"^add/$", "remap.views.add_project", name="add_project_location"),
    url(r"^add/details/$", "remap.views.add_project_details", name="add_project_details"),
)

views.py

def add_project_details(request):
if request.method == 'POST': # If the form has been submitted...
    locationForm = LocationForm(request.POST) 
    if locationForm.is_valid(): # All validation rules pass
        locality = locationForm.cleaned_data['locality']
        state = locationForm.cleaned_data['state']
        country = locationForm.cleaned_data['country']

        projectForm = ProjectForm(initial = { 
            'locality': locality, 
            'state': state, 
            'country': country, 
        })
        return render_to_response('map/add_project_details.html', {
            'projectForm': projectForm,
        }, context_instance = RequestContext(request))

    else:
        print locationForm.errors 
        return render_to_response('map/add_project_location.html', {
            'locationForm': locationForm,
        }, context_instance = RequestContext(request))
else:
    return HttpResponseRedirect('../') # Redirect to the location reg if site is requested w/o proper location 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:44:19+00:00Added an answer on May 24, 2026 at 9:44 pm

    There’s no cause to get irritated about Django doing exactly what it is designed to do.

    Your redirect is on the else clause corresponding to if request.method == 'POST'. So, it will only take effect if this is not a form submission. In other words, that view will never actually display an empty form.

    Then, depending on whether or not the POSTed form is valid, you display one of two templates. You’re not doing any redirecting at this point.

    However, even if you had asked Django to redirect when the form is invalid, I doubt you would get the result you want. This is because the rules of HTTP (not Django) say that you can’t redirect a POST – so your request to the redirected view would be a GET, without any of the invalid data or error messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Stackoverflow people, I am trying to write my own contact form in Django,
Hi Stackoverflow people, In the past, I always developed my Django projects locally with
Hi Stackoverflow people, I have trouble to render a crispy form with a class
Hellow stackoverflow people, I am pretty new to Cocoa. I have XCode 3.1 Situation:
I have found this example on StackOverflow: var people = new List<Person> { new
In stackoverflow, and some other websites where people submits questions or posts, there is
Hi Stackoverflow people, I am displaying a large form through a loop: <table> {%
Hi Stackoverflow people, I am confused with m2m queries in Django. I have a
Hi Stackoverflow people, I am implementing the MarkerCluster function for google map markers. I
Hello stackoverflow people! I've got a problem which I haven't been able to solve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.