Forms Part 5: Basic Form Validation

Forms are a big subject in Django. We have run through a lot when it comes to forms. We are concluding our series with Form Validation. This simple video will finalize everything we have done so far by allowing us to give feedback to our users when our form validation goes wrong.
from django.shortcuts import 
from django.template import RequestContext

from contact.forms import 

def suggestion(request):
    if request.method == "POST":

        form = SuggestionForm(request.POST)

        if(form.is_valid()):
            try:
                print(request.POST['title'])
                return redirect('/')
            except:
                pass
    else:
        form = SuggestionForm()

    return render_to_response('contact/suggestion.html',
                {'form': form},
                context_instance=RequestContext(request))
comments powered by Disqus