Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django grappelli seems unable to see all its media files

I have django 1.4 and grappelli 2.4.3 running on an Ubuntu server, which I'm viewing over a Windows networked system when in production. Everything works fine on the development server when I view it on the Ubuntu machine using RDP.

The relevant parts of settings.py are:

STATIC_ROOT = os.path.join(os.path.dirname(__file__), '../03_static_files/collected/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(os.path.dirname(__file__), '../03_static_files/'),
    os.path.join(os.path.dirname(__file__), '../03_static_files/admin/'),
    os.path.join(os.path.dirname(__file__), '../03_static_files/filebrowser/'),
    os.path.join(os.path.dirname(__file__), '../03_static_files/grappelli/'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # apps I added but didn't create
    'south',
    'grappelli',
    'filebrowser',
    'tinymce',
    'haystack',
    'gunicorn',
    'debug_toolbar',
    'taggit',

    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',

    # apps I created
    'community',
    'fts',
    'guidance',
    'news',
)

I've run collectstatic but the admin site is clearly only partially rendered. It's definitely picking up some CSS because some elements are styled. But it's not picking up others because it looks a mess. Neither my Nginx or Gunicorn error logs show any 404s, and I can download all the css and js files if I point my browser to them directly.

The admin site currently looks like this in both IE8 and IE9:

half-rendered grappelli

Everything else about the site runs fine. Django debug toolbar says the (working) development server version and the production version above are rendering identical templates. The normal django admin displays properly when grappelli is removed. I've tried changing my Nginx conf file from

location /admin/media/ {
    root /path/to/django/contrib;
}

to

location /admin/media/ {
    root /path/to/grappelli;
}

with no change. Can anyone tell me where I'm going wrong?

like image 574
cms_mgr Avatar asked Jan 28 '13 15:01

cms_mgr


3 Answers

Check the static media is defiantly there.

check all there os these settings...

STATIC_URL = '/static/' 
STATIC_ROOT is something like os.path.join(PROJECT_PATH, "static"),
ADMIN_MEDIA_PREFIX = '/static/grappelli/' (or whatever your static directory is)

next check your

DEBUG = False or True ?
TEMPLATE_DEBUG = DEBUG

If false, it will to serve files with nginx with it won't

Another example...

STATIC_URL = '/static/'
STATIC_ROOT = '/home/foo/devel/static'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/foo/devel/media'
# the following is deprecated but is it seems grappelly requires it
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"
STATIC_FILES = ()
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
like image 162
Glyn Jackson Avatar answered Sep 22 '22 15:09

Glyn Jackson


Another shot in the dark: Do you by chance have differing TEMPLATE_DIRS settings in development and production? Looking at the screenshot, this doesn't seem to be a problem with static files. Like diegueus9 already pointed out, the grappelli css styles appear to be loaded, but templates are the ones from stock Django admin.

like image 40
Dirk Eschler Avatar answered Sep 21 '22 15:09

Dirk Eschler


It seems that Django 1.4.3 introduced some changes to their admin static files that Grappelli didn't manage to follow yet. I did not take the time to check if it is an issue up to templates or static files level itself, but I came with a workaround.

You can either downgrade your Django setup to 1.4.2 until they get it fixed or, as I did, temporarily disable 'django.contrib.admin' in INSTALLED_APPS (just comment the line or anything as effective), run collectstatic -c and then enable admin back again. Either way, you'll have correct styles on your Grappelli deploy.

like image 41
emyller Avatar answered Sep 24 '22 15:09

emyller