Django grappelli seems unable to see all its media files

て烟熏妆下的殇ゞ 提交于 2019-12-10 14:01:10

问题


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:

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?


回答1:


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',
)



回答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.




回答3:


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.




回答4:


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',
)


来源:https://stackoverflow.com/questions/14565733/django-grappelli-seems-unable-to-see-all-its-media-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!