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 .
-
How do you serve your static files? Is your DEBUG variable in settings.py set to False? – Nihal Sangeeth Mar 10 '19 at 17:52
-
Yes , debug is false @NihalSangeeth – T.Pool Mar 10 '19 at 18:20
1 Answers
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

- 3,242
- 22
- 23

- 5,168
- 2
- 17
- 32
-
Please ignore step 8 (editing `wsgi.py`). That was for a much older version of WhiteNoise and it will not work for newer releases. – D. Evans Mar 11 '19 at 08:55
-
Thanks for the edit. I believe you are the owner of the project? Great work there. – Nihal Sangeeth Mar 11 '19 at 09:09
-