Django Admin not loading static files

13 hours ago 4
ARTICLE AD BOX

I am working on a web server project on raspberry pi. It's based on django and uses gunicorn for localhost web server and nginx as proxy to my LAN. On the main site '/' it shows django default site that says the installation was successfull, but when I want to open /admin it shows only the HTML and does not load static files. If I look into dev tools the site is sending GET request to for example: http://online-recepty.local/static/admin/css/dark_mode.css, but the request returns 404.

Django Admin Page Screenshot

I found this: Why gunicorn cannot find static files - stack overflow and I tried it and now gunicorn doesn't show error that it can't find static files, but the website still doesn't load it. Also I can't access static files using URL in browser if it helps.

The manage.py is in /home/user/onlineRecepty/manage.py

I tried to collect static files into /var/www/onlineRecepty/static/

settings.py:

... # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ STATIC_URL = "/static/" STATIC_ROOT = "/var/www/onlineRecepty/static/" ...

and I also then used command python3 manage.py collectstatic and it returned that 119 static files were successfully collected.

I added into /etc/nginx/sites-available/kucharka file /static/ to link into the folder:

server { listen 80; server_name online-recepty.local; location /static/ { root /var/www/onlineRecepty/static/; } location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }

I hope I've provided enough code for someone to help me.

THANK YOU SO MUCH FOR HELP!!

Read Entire Article