title: Django after login why the request.user is always anonymous?
body: <p><em><strong>I want to redirect a homepage after login in, but the request.user is always anonymous.Where the errors hide?</em></strong></p>
  
  <p>the code:
  urls.py</p>
  
  <pre><code>urlpatterns = patterns('',
          url(r'^login/$', login_view),
          url(r'^main/$', main_view,name='main'),
      )
  </code></pre>
  
  <p>i have a login form named forms.py</p>
  
  <pre><code>class LoginForm(forms.Form):
      username = forms.CharField(required=True,
              label='',
              max_length=12,
              error_messages={'required':'username'},
              widget=forms.TextInput(
                  attrs={'placeholder':'username',
                         'class':'form-control'}))
      password = forms.CharField(required=True,
              label='',
              max_length=12,
              min_length=6,
              error_messages={'required':'password'},
              widget=forms.PasswordInput(
                  attrs={'placeholder':'password',
                         'class':'form-control'}))
  
      def clean(self):
          if not self.is_valid():
              raise forms.ValidationError('username and password are required')
          else:
              cleaned_data = super().clean() 
  </code></pre>
  
  <p><strong>the view file:</strong></p>
  
  <pre><code>def login_view(request):
      if request.method == 'GET':  
          form = LoginForm(auto_id=False)  
          return render_to_response('game/login.html',
                  RequestContext(request, {'form': form,}))
      else:  
          form = LoginForm(request.POST)  
          if form.is_valid():  
              username = request.POST.get('username', '')  
              password = request.POST.get('password', '')  
              user = auth.authenticate(username=username,
                                       password=password)  
              if user is not None and user.is_active:  
                  auth.login(request, user)  
                  return render_to_response('game/main.html',
                          context_instance=RequestContext(request))
              else:  
                  return render_to_response('game/login.html',
                      RequestContext(request, 
                          {'form': form,'password_is_wrong':True}))  
          else:  
              return render_to_response('weapon/login.html',
                      RequestContext(request, {'form': form,}))  
  
  @login_required(login_url='/game/login/')
  def main_view(request):
      user = request.user
      return render_to_response('weapon/main.html',
                       {'user':user},
                       context_instance=RequestContext(request))
  </code></pre>
  
  <p>login.html include:</p>
  
  <pre><code>&lt;form class="form-signin" role="form" action="{% url 'game:main'  %}" method="post"&gt;
        {% csrf_token %}
  
          &lt;h2 class="form-signin-heading"&gt;Login in&lt;/h2&gt;
           {{ form.as_p }} 
          &lt;label class="checkbox"&gt;
            &lt;input type="checkbox" value="remember-me"&gt; remember me
          &lt;/label&gt;
          &lt;button class="btn btn-lg btn-primary btn-block" type="submit"&gt;Login&lt;/button&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p>main.html include:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
   {% if user.is_authenticated %}
      {{ user.username }} Successful
  {% else %}
      failed
  {% endif %}  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any suggestions would be much appreciated.</p>