Opened 15 years ago

Closed 15 years ago

#12038 closed (invalid)

http://docs.djangoproject.com/en/dev/topics/forms/ contact example

Reported by: ilkka Owned by: nobody
Component: Documentation Version: 1.1
Severity: Keywords: code example
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The example

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,
    })

Is tad more clear in this form

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: #invalid data, the bound form instance is passed on to the template.
            return render_to_response('contact.html', {'form': form}) 
    else:
        form = ContactForm() # An unbound form

   

Change History (1)

comment:1 by Russell Keith-Magee, 15 years ago

Resolution: invalid
Status: newclosed

I'm not sure what you're trying to make clearer, but your proposed improvement is fundamentally flawed - it doesn't return a rendered response on a GET.

Note: See TracTickets for help on using tickets.
Back to Top