Please help me understand the execution logic of a view. I have copied
the example from the official Django documentation:

def contact(request):
    if request.method == 'POST': # If the form has been submitted...
        form = ContactForm(request.POST) # A form bound to the POST
data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            return HttpResponseRedirect('/thanks/') # Redirect after
POST
    else:
        form = ContactForm() # An unbound form

    return render_to_response('contact.html', {
        'form': form,
    })


Lets imagine that I have clicked on a url that is mapped to the
contact view. Is this the correct execution logic:

1. The else part will execute and create an unbound ContactForm
instance that will be passed to the contact.html template
2. When the user clicks submit, the POST method will be executed, and
the user will be redirected to the url '/thanks/'

Please let me know if this is incorect? I'm just struggling to
understand how the same view gets executed twice - once for the
loading of the html page, and a second time for the POST method after
submitting. Also, should the unbound form logic not be above the POST
logic?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to