Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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: http://code.djangoproject.com/svn/django/trunk@5295 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d43522b077bb0c8070aba1821fe029b196cb93b8 1 parent 0f424f5
Russell Keith-Magee authored May 20, 2007

Showing 1 changed file with 6 additions and 3 deletions. Show diff stats Hide diff stats

  1. 9  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
321 321
 form::
322 322
 
323 323
     from django.shortcuts import render_to_response
  324
+    from django.http import HttpResponseRedirect
324 325
     from django import newforms as forms
325 326
 
326 327
     class ContactForm(forms.Form):
@@ -334,6 +335,7 @@ form::
334 335
             f = ContactForm(request.POST)
335 336
             if f.is_valid:
336 337
                 # ... do something with f.cleaned_data
  338
+                return HttpResponseRedirect('/url/on_success/')
337 339
         else:
338 340
             f = ContactForm()
339 341
         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
658 660
 with a view like this::
659 661
 
660 662
     def contact(request):
661  
-        form = ContactForm()
662 663
         if request.method == 'POST':
663  
-            new_data = request.POST.copy()
664  
-            form = ContactForm(new_data)
  664
+            form = ContactForm(request.POST)
665 665
             if form.is_valid():
666 666
                 # do form processing here...
  667
+                return HttpResponseRedirect('/url/on_success/')
  668
+        else:
  669
+            form = ContactForm()
667 670
         return render_to_response('contact.html', {'form': form})
668 671
 
669 672
 ...you can have a simple template that uses the shortcuts ``form.as_ul``,

0 notes on commit d43522b

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