Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render,redirect
- from django.contrib.auth import authenticate,login
- from django.views.generic import View
- from .forms import UserForm
- from .models import Album
- class UserFormView(View):
- form_class = UserForm
- template_name = 'music/registration_form.html'
- title = "Register"
- def get(self, request):
- form = self.form_class(None)
- return render(request, self.template_name, {'form': form})
- def post(self, request):
- form = self.form_class(request.POST)
- if form.is_valid():
- user = form.save(commit=False)
- #normalized data
- username = form.cleaned_data['username']
- password = form.cleaned_data['password']
- user.set_password(password)
- user.save()
- #returns user objects
- user = authenticate(username=username, password=password)
- if user is None:
- if user.is_active:
- login(request, user)
- return redirect('index') #This line though
- return render(request, self.template_name, {'form': form})
Add Comment
Please, Sign In to add comment