why my django admin site does not have the css style

后端 未结 19 1780
南笙
南笙 2020-12-02 07:49

I make a Django admin site using Django development version

But it does not have a CSS style :

\"alt

相关标签:
19条回答
  • 2020-12-02 08:14

    Failing after trying 1000s of suggestions, I finally found a solution that helped. Here is what I tried and what I was using. I am using django-1.11 and nginx web server. Firstly, I made sure that my CSS/js files are not getting 404 in browser's console. After that, I could see a warning

    Resource interpreted as Stylesheet but transferred with mime type text/plain

    I found the base.html in admin templates and removed

    type="text/css"

    and now the lines looks like this:

    <link rel="stylesheet"  href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" /> 
    

    This fixed the issue for me.

    0 讨论(0)
  • 2020-12-02 08:18

    If you are using Apache server to host your django site, you need to make sure the static alias point to your /directory to site/site_media/static/. If your static files are in /directory to site/site/site_media/static/, the previous Apache alias configuration will not work.

    0 讨论(0)
  • 2020-12-02 08:19

    In addition to many of the other answers being useful, I had a problem that hasn't yet been noted. After upgrading from Django 1.3 to 1.6, my static files directory had a broken symbolic link to the django admin static files.

    My settings.py was configured with:

    STATICFILES_DIRS = (
        '/var/www/static/my-dev',
    )
    

    According to this answer,

    Django will now expect to find the admin static files under the URL /admin/.

    I had a symbolic link /var/www/static/my-dev/admin which was set to:

    admin -> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/
    

    That location no longer exists in django 1.6, so I updated the link to:

    admin -> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/
    

    And now my admin site is working properly.

    0 讨论(0)
  • 2020-12-02 08:19

    Configuring static files Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.

    In your settings.py file, define STATIC_URL, for example:

    STATIC_URL = '/static/'
    

    for more details static files

    0 讨论(0)
  • 2020-12-02 08:20

    I read several other threads trying to fix this...resorted to an alias as in other threads. This assumes that your own custom app is serving static files correctly, which would indicate that your STATIC_ROOT and STATIC_URL have proper settings.

    STATIC_ROOT = ''
    STATIC_URL = '/static/'
    

    Then (from your static directory):

    ubuntu@ip-1-2-3-4:/srv/www/mysite.com/app_folder/static$ sudo ln -s /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/ admin
    

    Hope this helps someone...there are a lot of threads on this topic. :(

    0 讨论(0)
  • 2020-12-02 08:21

    Ensure that 'django.contrib.staticfiles' is in your INSTALLED_APPS in your settings.py

    0 讨论(0)
提交回复
热议问题