Opened 10 years ago

Closed 10 years ago

#23904 closed Cleanup/optimization (worksforme)

Forms Overview

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

Description

On the forms overview, the views.py snippet:
https://docs.djangoproject.com/en/1.7/topics/forms/

from django.shortcuts import render
from django.http import HttpResponseRedirect

def get_name(request):

# if this is a POST request we need to process the form data
if request.method == 'POST':

# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():

# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')

# if a GET (or any other method) we'll create a blank form
else:

form = NameForm()

return render(request, 'name.html', {'form': form})

If you call NameForm() #2nd to last line of code
Won't that cause an import error?

https://docs.djangoproject.com/en/1.7/topics/forms/

Change History (3)

comment:1 by Brett, 10 years ago

Component: UncategorizedDocumentation
Type: UncategorizedCleanup/optimization

comment:2 by Baptiste Mispelon, 10 years ago

Hi,

The assumption is that we're reusing the NameForm defined in the previous paragraph [1].

The whole section is meant to be read sequentially so I don't know if we need to make that more explicit.

What do you think?

Thanks.

[1] https://docs.djangoproject.com/en/1.7/topics/forms/#the-form-class

comment:3 by Tim Graham, 10 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top