Django Admin CSS missing

后端 未结 11 1066
醉梦人生
醉梦人生 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:59

    Django recommends that you deploy static files with a web server other than wsgi.

    1. In settings.py, set:

    STATIC_ROOT = 'static'

    1. Run python manage.py collectstatic, which will copy the Django admin static files to /path/to/project/static/

    2. Configure your static file server. If you use Nginx, you could add this config:

      location /static/ {                              
          alias /path/to/project/static/;  
          expires modified +1w;                        
      }  
      
    3. Reload your web server

    You should now have access to the static files.

    0 讨论(0)
  • 2020-12-24 02:00

    Also make sure that AppDirectoriesFinder is not commented, happens when you're trying to customize your own app structure. Unfortunatelly it's pointless to seek such information in official docs.

    STATICFILES_FINDERS = [
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    ]
    
    0 讨论(0)
  • 2020-12-24 02:06

    in my project, the solution is in settings.py, set:

    DEBUG = False # debug false mod not working css

    0 讨论(0)
  • 2020-12-24 02:06

    In settings.py Don't use tuple for the

    STATICFILES_DIRS =( os.path.join(BASE_DIR, 'static'), )

    you should use list,like this

    STATICFILES_DIRS =[ os.path.join(BASE_DIR, 'static'), ]

    0 讨论(0)
  • 2020-12-24 02:12

    One solution might be to add your local IP to the ALLOWED_HOSTS list in settings.py

    e.g.

    CURRENT_IP = '192.168.0.123'
    ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '0.0.0.0', CURRENT_IP]
    
    0 讨论(0)
提交回复
热议问题