6

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?

cms_mgr
  • 1,977
  • 2
  • 17
  • 31
  • i have the exact same problem but i'm using the django server – Asken Jan 31 '13 at 13:13
  • That's interesting to know because my setup is working fine on the development server, so whatever you're not doing in development is probably what I'm not doing in production! Please let me know how you fixed it when you do. – cms_mgr Jan 31 '13 at 13:18
  • I am having the same problem. So far, it seems to be a Grappelli issue that I'm yet to know about. – emyller Feb 06 '13 at 07:49

4 Answers4

2

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',
)
Glyn Jackson
  • 8,228
  • 4
  • 29
  • 52
2

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.

Dirk Eschler
  • 2,539
  • 1
  • 21
  • 41
  • No the `TEMPLATE_DIRS` are the same. I've updated the question to say that, according to Django debug toolbar at least, the same templates are being rendered in both development and production. I'm trying to add the relevant parts of settings.py to the question but myOpenID seems to be down just now so I can't log in from the machine with the code on it. – cms_mgr Feb 06 '13 at 15:57
1

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.

emyller
  • 2,648
  • 1
  • 24
  • 16
  • This answer makes the most sense to me but the suggested workaround didn't work (none of the other suggested answers have worked thus far either). I haven't tried the downgrade yet, I'll keep that as an option of last resort. – cms_mgr Feb 06 '13 at 11:20
  • Downgrading Django for collecting static data isn't a beautiful option, but it would surely work flawlessly if you want to run Grappeli for now. Temporarily removing Django's admin worked for me, though. – emyller Feb 08 '13 at 17:50
0

My best guest without look your settings.py is that your application "grappelli" is installed after django´s admin and not before. Look that warning in the setup doc

Clearly your css and js are right, but doesn´t renderize well because you application is rendering the templates of django.contrib.admin.

Please make sure of put grappelli before:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'grappelli',
    'django.contrib.admin',
)
diegueus9
  • 29,351
  • 16
  • 62
  • 74