Advertisement
Guest User

django: working with forms 1

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