Django Admin CSS missing

后端 未结 11 1065
醉梦人生
醉梦人生 2020-12-24 01:23

I\'ve been messing around with the new collectstatic command and have got it working for my normal pages. That is to say, I am able to load my css at this locat

相关标签:
11条回答
  • 2020-12-24 01:46

    It seems dumb, but I actually had this exact issue and the solution was to set DEBUG=False to DEBUG=True on my local dev environment. When debug is set to False, it thinks it's in a production environment which relies on a place to put static files, such as /var/www/html/static, whereas the debug set to True just uses the local directory.

    0 讨论(0)
  • 2020-12-24 01:48

    In Django 1.4 ADMIN_MEDIA_PREFIX is deprecated. Here are the steps I followed to catch up with these somewhat recent Django changes:

    1. in settings.py, add django.contrib.staticfiles to INSTALLED_APPS

    2. in settings.py define STATIC_URL — the staticfiles app won't run without it. While using runserver they'll get handled magically, but when you deploy, this needs to be a location where those resources can be fetched by a browser.

    I think that's all there was to it.

    0 讨论(0)
  • 2020-12-24 01:48

    I'm using Django 1.4.3

    What did NOT work for me: No matter how much I edited ADMIN_MEDIA_PREFIX in settings.py I noticed no change in the HTML generated for the Django Admin pages. It always says /media/admin/base.css when I view the source.

    What DID work for me. Copied the 'admin' folder from /django/contrib/admin/static/ and pasted it into my projects 'media' folder

    Now it works great.

    0 讨论(0)
  • 2020-12-24 01:48

    You need a trailing slash in your ADMIN_MEDIA_PREFIX setting.

    Change to:

    ADMIN_MEDIA_PREFIX = '/static/admin/' 
    
    0 讨论(0)
  • 2020-12-24 01:58

    I'm using chef to auto-build my django server on an AWS Ubuntu server. This post helped, but what I wound up doing was to add the directory to the package admin static pages in a local_setings.py: https://github.com/jaycrossler/geoq-chef-repo/blob/master/cookbooks/geoq/templates/default/local_settings.py.erb#L16

    (added to local_settings.py or to settings.py):
    
    STATICFILES_DIRS = ('<%= node['geoq']['virtualenv']['location'] %>/local/lib/python2.7/site-packages/django/contrib/admin/static/',)
    

    This resulted in local_settings.py having:

    STATICFILES_DIRS = ('/var/lib/geoq/local/lib/python2.7/site-packages/django/contrib/admin/static/',)
    

    Note, that if you have other items already in your STATICFILES_DIRS, you might want to append to the list, rather than overwriting it.

    0 讨论(0)
  • 2020-12-24 01:58

    you need

    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    
    0 讨论(0)
提交回复
热议问题