Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin missing static files when using gunicorn web server

Tags:

django

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

like image 578
user1283776 Avatar asked Dec 12 '15 16:12

user1283776


People also ask

Does Gunicorn serve static files?

Does Gunicorn serve static files? Your application will now serve static assets directly from Gunicorn in production.

Where are Django static files stored?

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.

How do I serve static files in Django?

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 .

How does Django handle static and media files?

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/ .


1 Answers

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

like image 156
miki725 Avatar answered Nov 15 '22 00:11

miki725