When I run my project with runserver
, django admin is showing with static files. Everything looks pretty.
But when I run my project with the gunicorn
web server, static files for the django admin are not found:
Not Found: /
Not Found: /favicon.ico
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/login.css
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/dashboard.css
Why are these static files not served out of the box?
What steps should I make to serve the static files for django admin via gunicorn
?
I'm using Django 1.9 with python 3.4
Does Gunicorn serve static files? Your application will now serve static assets directly from Gunicorn in production.
Files are searched by using the enabled finders . The default is to look in all locations defined in STATICFILES_DIRS and in the 'static' directory of apps specified by the INSTALLED_APPS setting.
Serving the site and your static files from the same serverPush your code up to the deployment server. On the server, run collectstatic to copy all the static files into STATIC_ROOT . Configure your web server to serve the files in STATIC_ROOT under the URL STATIC_URL .
Don't put any static files in the STATIC_ROOT directory. That's where the static files get copied to automatically after you run collectstatic . Instead, always put them in the directories associated with the STATICFILES_DIRS setting or <APP_NAME>/static/ .
You need to collect all static files via manage.py collectstatic
command. More information in the docs - https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#django-admin-collectstatic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With