title: Django @login_required decorator not functioning properly
body: <p>I am developing a web-app which will support multiple customers.  All customers will be housed in the same database.  An authentication group will be created for each customer, permissions will be assigned at the group level to ensure that only database resources pertaining to that particular customer can be accessed.  Users will be bound to the group for their company and permissions overrides (if desired) will be handled at this level.</p>
  
  <p>Each customer will be able to log into Django Admin, again only having access to database resources for their company.  On the front end, each customer will have their own URL.  For example:</p>
  
  <pre><code>http://127.0.0.1:8000/customer1
  http://127.0.0.1:8000/customer2
  </code></pre>
  
  <p>When a customer accesses their front-end URL directly, I want to force them to log in.  I want to use the @login_required decorator to redirect them to the Django Admin login page and upon successful authentication I want to pass the user through to the URL they requested in the first place.  For example</p>
  
  <pre><code>* User puts 'http://127.0.0.1:8000/customer1' into their browser
  * Browser redirects to authentication page
  * User provides credentials and authenticates successfully
  * User is passed through to 'http://127.0.0.1:8000/customer1'
  </code></pre>
  
  <p>Currently I believe that I have things configured correctly (I'm probably wrong else I wouldn't be posting this) but the decorator seems to not be called/invoked/functioning properly.  When the user inputs <a href="http://127.0.0.1:8000/customer1" rel="nofollow">http://127.0.0.1:8000/customer1</a> URL into their browser, they go straight to the URL as before (page loads successfully) but with no redirect occurring for the desired authentication behavior.</p>
  
  <p><strong>ROOT URL FILE (\DJANGO_PROJECT\DJANGO_PROJECT\urls.py):</strong></p>
  
  <pre><code>from django.conf.urls import url, include
  from django.contrib import admin
  
  urlpatterns = [
      url(r'', include('basesite.urls', namespace='basesite')),
      url(r'^admin/', admin.site.urls),
      url(r'^customer1/', include('customer1.urls', namespace='customer1')),
      url(r'^customer2/', include('customer2.urls', namespace='customer2')),
  ]
  </code></pre>
  
  <p><strong>CUSTOMER1 URL FILE (\DJANGO_PROJECT\customer1\urls.py):</strong></p>
  
  <pre><code>from django.shortcuts import render, get_object_or_404
  from django.contrib.auth.decorators import login_required
  from customer1.models import Company
  
  @login_required(login_url='admin/')
  def index(request):
      companies = Company.objects.all()
      context = { 'companies': companies }
      return render(request, 'customer1/index.html', context)
  </code></pre>
  
  <p>Thanks in advance for any assistance with this problem.</p>