adlnet / ADL_LRS

ADL's Open Source Learning Record Store (LRS) is used to store learning data collected with the Experience API.
https://lrs.adlnet.gov
Apache License 2.0
308 stars 146 forks source link

No admin and no login when using uWSGI. #380

Closed evermax closed 8 years ago

evermax commented 8 years ago

Hi!

Sorry to bother you again, this has possibly way more to do with django than the ADL LRS but I can't access the admin part and even the /login/ URLs when I am running the project with uWSGI. Any idea on that issue?

evermax commented 8 years ago

Perhaps I should also give my configuration file:

[uwsgi]

# Django-related settings
# the base directory of django project
chdir = /workspace/ADL_LRS
# Django's wsgi file
module = adl_lrs.wsgi:application
env = DJANGO_SETTINGS_MODULE = adl_lrs.settings
# virtualenv path
home = /workspace/env
enable-threads = true
workers = 5
processes = 5
harakiri = 10
vacuum = true
master = true
http-socket = :8000
daemonize = /workspace/ADL_LRS/logs/lrs_uwsgi.log

And this is how I launch it: /workspace/env/bin/uwsgi --emperor /etc/uwsgi/vassals

The configuration file above is inside /etc/uwsgi/vassals

ljwolford commented 8 years ago

Hmm does it say it's just not found? There is an issue with django 1.4 that started happening where it didn't copy over the admin files or extensions. If you look at the end of the fabfile.py file, you'll see where there are commands written to copy it over. If you look inside /env/local/lib/python2.7/site-packages/django_extensions/ hopefully you see an admin folder and some other ones. If you don't, try running those rsync commands manually.

evermax commented 8 years ago

There is an admin folder inside env/bin/local/python2.7/site-packages/django_extensions/.

Here is the Traceback

Environment:

Request Method: GET
Request URL: http://192.168.99.100:8080/admin/

Django Version: 1.4
Python Version: 2.7.11
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'adl_lrs',
 'lrs',
 'oauth_provider',
 'oauth2_provider.provider',
 'oauth2_provider.provider.oauth2',
 'django.contrib.admin',
 'django_extensions',
 'jsonify',
 'south',
 'endless_pagination')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'adl_lrs.utils.AllowOriginMiddleware.AllowOriginMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/workspace/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper
  213.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  195.                 return self.login(request)
File "/workspace/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in login
  326.         return login(request, **defaults)
File "/workspace/env/lib/python2.7/site-packages/django/views/decorators/debug.py" in wrapper
  69.             return view(request, *args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/contrib/auth/views.py" in login
  60.     current_site = get_current_site(request)
File "/workspace/env/lib/python2.7/site-packages/django/contrib/sites/models.py" in get_current_site
  92.         current_site = Site.objects.get_current()
File "/workspace/env/lib/python2.7/site-packages/django/contrib/sites/models.py" in get_current
  25.             current_site = self.get(pk=sid)
File "/workspace/env/lib/python2.7/site-packages/django/db/models/manager.py" in get
  131.         return self.get_query_set().get(*args, **kwargs)
File "/workspace/env/lib/python2.7/site-packages/django/db/models/query.py" in get
  366.                     % self.model._meta.object_name)

Exception Type: DoesNotExist at /admin/
Exception Value: Site matching query does not exist.

Somehow, it goes through the admin module but still doesn't find it..

ljwolford commented 8 years ago

Does your admin location directive in your nginx config file have the correct admin directory?

evermax commented 8 years ago

I don't have any, I copied the config from here Using Nginx for Production. Is there something to add?

evermax commented 8 years ago

Here is my config:

upstream lrs_server {
    server 127.0.0.1:8000 fail_timeout=0;
}
server {
    listen 8080; #or whatever port you want to use
    server_name _;

    #full path to the project dir - the dir that contains the urls.py file
    root /workspace/ADL_LRS/adl_lrs;

    access_log /workspace/ADL_LRS/logs/nginx_access.log;
    error_log /workspace/ADL_LRS/logs/nginx_error.log;
    location / {
        try_files $uri @proxy_to_lrs;
        client_max_body_size 2M; #whatever limit you want to put on incoming request body sizes
    }

    location @proxy_to_lrs {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://lrs_server;
    }

    location /static/ {
        autoindex on;
        root /workspace/ADL_LRS/adl_lrs;
    }

    location /static/endless_pagination {
        autoindex on;
        expires 1w;
        alias /workspace/env/lib/python2.7/site-packages/endless_pagination/static/endless_pagination;
    }

    location /static/admin {
        autoindex on;
        expires 1w;
        alias /workspace/env/lib/python2.7/site-packages/django/contrib/admin/static/admin;
    }
}
ljwolford commented 8 years ago

After some quick searching, you may be missing the Site in the DB. Try opening the shell and trying this:

from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.example.com', name='example.com')

Found from here: http://stackoverflow.com/questions/9736975/django-admin-doesnotexist-at-admin

evermax commented 8 years ago

Thanks, I didn't really know what to look for. Sorry to open a issue for that. I actually removed this part 'django.contrib.sites' and now it works.