views.py 681 B

1234567891011121314151617181920212223242526
  1. from django.shortcuts import render
  2. from . forms import VoterRegistrationForm
  3. from . models import *
  4. # Create your views here.
  5. def index(request):
  6. voter_registration_form = VoterRegistrationForm()
  7. if request.method == 'POST':
  8. voter_registration_form = VoterRegistrationForm(request.POST)
  9. if voter_registration_form.is_valid():
  10. print('Valid')
  11. print(voter_registration_form.cleaned_data)
  12. else:
  13. print('Invalid')
  14. questions = Question.objects.all()
  15. context = {
  16. 'form': voter_registration_form,
  17. 'questions': questions,
  18. }
  19. return render(request, 'vote/index.html', context=context)