Admin login returns 405 Not Allowed

477 views
Skip to first unread message

Peter Laudenslager

unread,
Sep 4, 2016, 10:36:29 PM9/4/16
to Django users
Hi All,

Having trouble moving my Django site into production.  I can hit pages for my application (no authentication required), and they all seem to work correctly.  When I connect to the default admin page, I see the correct login dialog box.  When I submit my credentials, I get a 405 Not Allowed page returned by Nginx.  I am sure that I have correct credentials, and would not expect this page returned even if my credentials were incorrect.

Steps to recreate:
  1. from my laptop browser, connect to www.mysite.com/admin
  2. see default django login screen
  3. type known good account credentials
  4. see 405 Not Allowed page returned
What I expect to happen:

Following steps 1-3 above, in step 4, I expect to see either the default Django admin screen, or the default Django failed login screen (looks just like the login, with an error message).

The admin login behaves correctly on my laptop, but not on the production server.

Configurations between laptop (development) and production:
  1. production uses Nginx 1.4.6 and Gunicorn 17.5 on Ubuntu Linux 14.04.5
  2. laptop is MacOS 10.11.6 running the Django 1.10.1 development server (manage.py run server)
  3. I have collected static files (so far, they only exist for the built-in admin) into a static directory in the root of the django project (one level up from manage.py)

What I have tried:


Peter Laudenslager

unread,
Sep 5, 2016, 12:43:05 AM9/5/16
to Django users
Sorry - somehow posted too early.

For a moment I thought I had this sorted. I had slightly different versions of Django between my development and production environments, and some of the static files for the admin pages had changed. It made sense that when Nginx redirected the static file requests, the new resources weren't there. Upgraded both environments to the latest Django (now 1.10.1), recollected static files, and got it to work.

Just to prove the point, I logged out, and tried to login with a different account, but got the 405 page again. So I tried the first account again with no success. Except for that one successful login, everything continues to return the 405 error.

From the errors in the Django log, it still seems like I may be missing a static file, or maybe a permissions problem on a directory, but no clear pointer to a specific file or directory.

Anyone have any tips on how to troubleshoot this?

Peter Laudenslager

unread,
Sep 5, 2016, 4:45:28 PM9/5/16
to Django users
Here is the specific error logged by Django's debug logger:

Exception while resolving variable 'is_popup' in template 'admin/login.html'.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 907, in _resolve_lookup
    (bit, current))  # missing attribute
VariableDoesNotExist: Failed lookup for key [is_popup] in u"[{'False': False, 'None': None, 'True': True}, {u'csrf_token': <SimpleLazyObject: <function _get_val at 0x7f96262e01b8>>, 'user': <SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x7f9626fdbc10>>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7f9626e13b90>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'SUCCESS': 25, 'ERROR': 40}, 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x7f9626fe0590>, u'request': <WSGIRequest: GET '/admin/login/?next=/admin/'>}, {}, {'username': u'', 'app_path': u'/admin/login/?next=/admin/', 'available_apps': [], 'site_name': 'app_server', 'form': <AdminAuthenticationForm bound=False, valid=Unknown, fields=(username;password)>, 'title': u'Log in', 'site_header': <django.utils.functional.__proxy__ object at 0x7f962c92bc50>, 'site': <django.contrib.sites.requests.RequestSite object at 0x7f9626fe9090>, 'next': u'/admin/', 'site_title': <django.utils.functional.__proxy__ object at 0x7f962c92b590>, u'LANGUAGE_CODE': 'en-us', 'has_permission': False, 'site_url': '/', u'LANGUAGE_BIDI': False}]" 

Peter Laudenslager

unread,
Sep 5, 2016, 5:05:32 PM9/5/16
to Django users
PARTIALLY SOLVED!!

The trouble seems to be with memcached.  I commented out references to memcached in the nginx configuration, and things started working properly.

I assume the admin page can be used with memcached, but something is wrong with my configuration.  Maybe related to the post command?  (so far, the rest of my site uses "get" only, other than the admin pages).

below is a snip from the nginx configuration file (in sites-available).   The memcached lines are commented out:

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
        
        #set $memcached_key "$uri?$args";
        #memcached_pass 127.0.0.1:11211;
        #error_page 404 502 504 = @fallback;
    }
    
    location @fallback {
    proxy_pass http://app_server;
    }

Reply all
Reply to author
Forward
0 new messages