title: django - middleware issue
body: <p>I want to put a login form everywhere on my website, after following a few SO answers I decide to write my own middleware like this:</p>
  
  <pre><code>class LoginFormMiddleware(object):
  '''
  Put a login form in everypage of the website
  '''
  def process_request(self, request):
      # if the top login form has been posted
      if request.method == 'POST': 
          if 'logout_submit' in request.POST:
              # log the user out
              from django.contrib.auth import logout
              logout(request)
              form = LoginForm()
          elif 'login_submit' in request.POST:
              # validate the form
              form = LoginForm(data=request.POST)
              if form.is_valid():
                  # log the user in
                  from django.contrib.auth import login
                  login(request, form.get_user())
          else:
              form = LoginForm(request)
      else:
          form = LoginForm(request)
      # attach the form to the request so it can be accessed 
      # within the templates
      request.login_form = form
  </code></pre>
  
  <p>in my settings.py, I have:</p>
  
  <pre><code>import django.conf.global_settings as DEFAULT_SETTINGS
  ...
  MIDDLEWARE_CLASSES = DEFAULT_SETTINGS.MIDDLEWARE_CLASSES + (
      'base.mymiddleware.LoginFormMiddleware',
  )
  TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
      'django.core.context_processors.request',
  )
  </code></pre>
  
  <p>The form, in base.html to be accesed from everywhere, looks like this:</p>
  
  <pre><code>{% if user.is_authenticated %}
              &lt;div class="login_box"&gt;
                  &lt;form action="/myapp/logout/" method="post"&gt;{% csrf_token %}
                      &lt;div class="col2"&gt;&lt;a&gt;{{ user.username }}&lt;/a&gt;&lt;/div&gt;
                      &lt;div class="col3"&gt;&lt;input type="submit" value="Logout" name="logout_submit"/&gt;&lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          {% else %}
                  &lt;form action="." method="post"&gt;
                      {% csrf_token %}
                      &lt;div class="login_box"&gt;
                          &lt;div class="error_box"&gt;
                              {% if request.login_form.errors %}
                                  Incorrect User/Password
                              {% endif %}
                          &lt;/div&gt;
                          &lt;div class="col00"&gt; &lt;h4&gt;{{ request.login_form.username.label_tag }}&lt;/h3&gt;&lt;/div&gt;
                          &lt;div class="col11"&gt;{{ request.login_form.username }}&lt;/div&gt;
                          &lt;div class="col22"&gt;&lt;h4&gt;{{ request.login_form.password.label_tag }}&lt;/h3&gt;&lt;/div&gt;
                          &lt;div class="col33"&gt;{{ request.login_form.password }}&lt;/div&gt;
                          &lt;div class="col44"&gt;&lt;input type="submit" value="Login" name="login_submit"/&gt;&lt;/div&gt;
                          &lt;input type="hidden" name="next" value="{{ request.get_full_path }}" /&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
          {% endif %}
  </code></pre>
  
  <p>Login works normally but, after doing it, each time I make a GET request user.is_authenticated seems to return false cause what I see is an empty LoginForm instead of the logout form.</p>
  
  <p>I dont know if the problem is in my middleware (when request.method != 'POST' it returns form = LoginForm(request)) or it is something I am missing in my settings, or maybe using middleware for this was not a great idea...</p>