Guest User

django: working with forms 1

a guest
May 28th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1.  
  2.  
  3. def contact(request):
  4.     if request.method == 'POST': # If the form has been submitted...
  5.         # ContactForm was defined in the previous section
  6.         form = ContactForm(request.POST) # A form bound to the POST data
  7.         if form.is_valid(): # All validation rules pass
  8.             # Process the data in form.cleaned_data
  9.             # ...
  10.             return HttpResponseRedirect('/thanks/') # Redirect after POST
  11.     else:
  12.         form = ContactForm() # An unbound form
  13.  
  14.     return render(request, 'contact.html', {
  15.         'form': form,
  16.     })
Advertisement
Add Comment
Please, Sign In to add comment