When I run, from the command line,
python manage.py runserver mywebsite.com:8099
the css works fine. But when I use the systemd service with Gunicorn socket, the app works but without the css. Even if I use the following command: gunicorn demo.wsgi:application, the app works fine but without the css.
Excerpt from my settings.py:
STATIC_URL = "static/"
STATICFILES_DIRS = [
BASE_DIR / "mystaticfiles"
]
Excerpt from my nginx config file:
location /static/ {
root /root/djdeploy/demo/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
My Django project working directory is: /root/djdeploy/demo/,
I have put my css files in the following folder: /root/djdeploy/demo/mystaticfiles
2
Answers
instead of this:
The CSS works when you do
python manage.py runserver
because it knows where to find static files in your code. On the other hand, gunicorn doesn’t know where to look for them.You need to set
STATIC_ROOT
and runpython manage.py collectstatic
on your server. You already have nginx set up to serve the files once you collect them to the location that nginx will look for them.See the official documentation for more details about deploying. Also see the section on configuring static files.