Guest User

Untitled

a guest
Jan 5th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class RegistrationView(View):
  2. template_name = 'registration.html'
  3.  
  4. def get(self, request):
  5. form = UserCreationForm(request.POST)
  6. return render(request, self.template_name, {'form': form})
  7.  
  8. def post(self, request, *args, **kwargs):
  9. form = UserCreationForm(request.POST)
  10. if form.is_valid():
  11. form.save()
  12. username = form.cleaned_data.get('username')
  13. raw_password = form.cleaned_data.get('password1')
  14. user = authenticate(username=username, password=raw_password)
  15. login(request, user)
  16. return redirect('main_page')
  17. return render(request, self.template_name, {'form': form})
Add Comment
Please, Sign In to add comment