title: Django CustomMiddleware causing csrf_token issues during log in
body: <p>I have been trying to implement this logic:</p>
  
  <p>Whenever a user signs up, confirms his email, his account is active. However, in order to let the user gain full access to the website, he must enter some data first about his own self. I call it complete-profile.</p>
  
  <p>I figured making a middleware is a good way to implement the logic. So I wrote the following:</p>
  
  <pre><code>class CompleteProfileMiddleware:
      def __init__(self, get_response):
          self.get_response = get_response
  
          # One-time configuration and initialization.
  
      def __call__(self, request):
          # Code to be executed for each request before
          # the view (and later middleware) are called.
  
          response = self.get_response(request)
  
          if request.path == "/account/" + request.user.username + '/complete-registration/':
              pass
          elif request.user.is_anonymous:
              pass
          elif request.user.is_superuser:
              pass
          elif request.user.student.complete_profile:
              pass
          elif not request.user.student.complete_profile:
              return redirect('/account/' + request.user.username + '/complete-registration/')
  
          # Code to be executed for each request/response after
          # the view is called.
  
          return response
  </code></pre>
  
  <p>However, now, for accessing the complete profile page, people need to log in first. And during the log in process, it gives issues with the csrf token as: <code>Forbidden. CSRF verification failed. Request aborted.</code></p>
  
  <p>If I remove the middleware everything starts working again, so the issue has to be here.</p>
  
  <p>Here's the login template:</p>
  
  <pre><code>    &lt;div class="main"&gt;
  
          &lt;section class="signup"&gt;
              &lt;div class="container"&gt;
                  &lt;div class="row"&gt;
                  &lt;div class="signup-content col-sm-12"&gt;
                      &lt;form id="signup-form" class="signup-form" method="post" action="{% url 'login' %}"&gt;
                          {% csrf_token %}
                          &lt;h2 class="form-title"&gt;Log In&lt;/h2&gt;
                              {{ form | crispy}}
                              &lt;input type="submit" style="margin-top: 10px" value="Login" class="button" id="" /&gt;
                              &lt;input type="hidden" name="next" value="{{ next }}" /&gt;
                      &lt;/form&gt;
                      &lt;div class="col-sm-12" style="text-align: right; margin-top: 5px"&gt;
                          &lt;a href="{% url 'password_reset' %}"&gt;Forgot Password?&lt;/a&gt;
  
                      &lt;/div&gt;
                      &lt;p class="loginhere"&gt;
                          New Here ? &lt;a href="/account/register" class="loginhere-link"&gt;Create an account here&lt;/a&gt;
                      &lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
                  &lt;/div&gt;
          &lt;/section&gt;
  
      &lt;/div&gt;
  </code></pre>