views.py 684 B

12345678910111213141516171819
  1. from django.contrib.auth import login, authenticate
  2. from django.contrib.auth.forms import UserCreationForm
  3. from django.shortcuts import render, redirect
  4. def signup(request):
  5. if request.method == 'POST':
  6. form = UserCreationForm(request.POST)
  7. if form.is_valid():
  8. form.save()
  9. username = form.cleaned_data.get('username')
  10. raw_password = form.cleaned_data.get('password1')
  11. user = authenticate(username=username, password=raw_password)
  12. login(request, user)
  13. return redirect('films:home')
  14. else:
  15. form = UserCreationForm()
  16. return render(request, "signup/signup.html", {'form': form})