-2

I have django admin panel working on a vps ( Windows Server 2012 ) , Why it is not showing any css styles or boostrap ? it is showing just html and nothing else .

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
T.Pool
  • 145
  • 1
  • 2
  • 13

1 Answers1

0

https://docs.djangoproject.com/en/2.1/howto/static-files/

During development, if you use django.contrib.staticfiles, this will be done automatically by runserver when DEBUG is set to True (see django.contrib.staticfiles.views.serve()).

So when you change DEBUG=False to move out of development, Django runserver will no longer automatically serve static files. Here is an alternate method using http://whitenoise.evans.io/en/stable/django.html

whitenoise for serving staticfiles in deployment

1) pip install whitenoise

2) Add 'whitenoise' to installed_apps

3) Give STATIC_ROOT to a folder like:

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

4) Run to collect staticfiles in STATIC_ROOT directory

python manage.py collectstatic

5)Add STATICFILES_STORAGE(optional)

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

6) Add in middleware before everything except 'django.middleware.security.SecurityMiddleware', like:

MIDDLEWARE_CLASSES = [
  'django.middleware.security.SecurityMiddleware',
  'whitenoise.middleware.WhiteNoiseMiddleware',
   ...
]

7)Change to DEBUG=False in settings.py

More details here http://whitenoise.evans.io/en/stable/django.html

D. Evans
  • 3,242
  • 22
  • 23
Nihal Sangeeth
  • 5,168
  • 2
  • 17
  • 32