Skip to content
Browse files

Modified the example views in newforms.txt to include a HttpResponseR…

…edirect (as per best practice), and remove a duplicated form instantiation.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 0f424f5 commit d43522b077bb0c8070aba1821fe029b196cb93b8 @freakboy3742 freakboy3742 committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 docs/newforms.txt
9 docs/newforms.txt
@@ -321,6 +321,7 @@ Putting this all together, here is a simple view method that uses our contact
from django.shortcuts import render_to_response
+ from django.http import HttpResponseRedirect
from django import newforms as forms
class ContactForm(forms.Form):
@@ -334,6 +335,7 @@ form::
f = ContactForm(request.POST)
if f.is_valid:
# ... do something with f.cleaned_data
+ return HttpResponseRedirect('/url/on_success/')
f = ContactForm()
return render_to_response('contact.html', {'form': f})
@@ -658,12 +660,13 @@ these parts from the template designer's point of view. Assuming you start
with a view like this::
def contact(request):
- form = ContactForm()
if request.method == 'POST':
- new_data = request.POST.copy()
- form = ContactForm(new_data)
+ form = ContactForm(request.POST)
if form.is_valid():
# do form processing here...
+ return HttpResponseRedirect('/url/on_success/')
+ else:
+ form = ContactForm()
return render_to_response('contact.html', {'form': form}) can have a simple template that uses the shortcuts ``form.as_ul``,

0 comments on commit d43522b

Please sign in to comment.
Something went wrong with that request. Please try again.