title: Django: How to login user directly after registration using generic CreateView
body: <p>With django generic CreateView I can create a new user account, but how can I login this user automatically after registration using this technique?  </p>
  
  <p>urls.py</p>
  
  <pre><code>...    
  url( r'^signup/$', SignUpView.as_view(), name = 'user_signup' ),
  ...
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class SignUpView ( CreateView ) :    
      form_class = AccountCreationForm
      template_name = 'accounts/signup.html'
      success_url = reverse_lazy( 'home' )
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class AccountCreationForm ( forms.ModelForm ) :        
      def __init__( self, *args, **kwargs ) :
          super( AccountCreationForm, self ).__init__( *args, **kwargs )
          for field in self.fields :
             self.fields[field].widget.attrs['class'] = 'form-control'
  
      password1 = forms.CharField( label = 'Password', widget = forms.PasswordInput )
      password2 = forms.CharField( label = 'Password confirmation', widget = forms.PasswordInput )
  
      class Meta :
          model = User
          fields = ( 'email', 'first_name', )
  
      def clean_password2 ( self ) :
          # Check that the two password entries match
          password1 = self.cleaned_data.get( "password1" )
          password2 = self.cleaned_data.get( "password2" )
          if password1 and password2 and password1 != password2:
              raise forms.ValidationError( "Passwords don't match" )
          return password
  
      def save( self, commit = True ) :
          # Save the provided password in hashed format
          user = super( AccountCreationForm, self ).save( commit = False )
          user.set_password( self.cleaned_data[ "password1" ] )
          if commit:
              user.save()
          return user
  </code></pre>