def campaign(request): if request.method == 'POST': form = CampaignForm(request.POST) if form.is_valid(): return HttpResponseRedirect('/') else: form = CampaignForm() return render(request, 'campaign.html',{ form : form, })
def contact(request): if request.method == 'POST': # If the form has been submitted... form = CampaignForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... return HttpResponseRedirect('/thanks/') # Redirect after POST else: form = CampaignForm() # An unbound form return render(request, 'politician/campaign.html', { 'form': form, })