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/
--
Ticket URL: <https://code.djangoproject.com/ticket/23904>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Documentation
* needs_better_patch: => 0
* type: Uncategorized => Cleanup/optimization
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23904#comment:1>
Comment (by bmispelon):
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
--
Ticket URL: <https://code.djangoproject.com/ticket/23904#comment:2>
* status: new => closed
* resolution: => worksforme
--
Ticket URL: <https://code.djangoproject.com/ticket/23904#comment:3>