SHARE
TWEET

Untitled

a guest Aug 13th, 2016 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.contrib.auth import authenticate, login
  2. from django.contrib.auth.forms import UserCreationForm
  3. from django.core.urlresolvers import reverse
  4. from django.views.generic.edit import CreateView
  5.  
  6. class SignUp(CreateView):
  7.     form_class = UserCreationForm
  8.     template_name = 'sign_up.html'
  9.  
  10.     def form_valid(self, form):
  11.         self.object = form.save()
  12.         user = authenticate(
  13.             username=form.cleaned_data['username'],
  14.             password=form.cleaned_data['password1']
  15.         )
  16.         login(self.request, user) # doesn't work :(
  17.         return super(SignUp, self).form_valid(form)
  18.  
  19.     def get_success_url(self):
  20.         return reverse('personal-info',
  21.             kwargs={ 'slug': self.request.user.username })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top