static files for django admin can't be found while running asgi server

170 Views Asked by At

Here is my settings.py

# ...other settings

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = 'static/'

# ...other settings

Then I run

python manage.py collectstatic

uvicorn Django_Channels.asgi:application --port 8000 --workers 4 --log-level debug --reload

this collects static (after that I do have static folder at the root folder), starts the asgi server, but when I go to the admin page it looks like without any CSS or JS files. Just a bunch of unorganised text.

Here are the logs from terminal:

Here what logs look likeINFO:     
127.0.0.1:51770 - "GET /static/admin/css/dashboard.css HTTP/1.1" 404 Not Found
Not Found: /static/admin/css/responsive.css
INFO:     127.0.0.1:51770 - "GET /static/admin/css/responsive.css HTTP/1.1" 404 Not Found
Not Found: /static/admin/js/theme.js
INFO:     127.0.0.1:51769 - "GET /static/admin/js/theme.js HTTP/1.1" 404 Not Found
Not Found: /static/admin/js/nav_sidebar.js
INFO:     127.0.0.1:51770 - "GET /static/admin/js/nav_sidebar.js HTTP/1.1" 404 Not Found

I am always having a bad time with staticfiles, could please somebody tell me what am I doing wrong?

1

There are 1 best solutions below

0
On

As you can see in related questions and in the django docs, static files can be served when you set DEBUG=True (for your development purposes only). Otherwise you have to include the static files path into your web server configuration.

Serving the files

In addition to these configuration steps, you’ll also need to actually serve the 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()).

This method is grossly inefficient and probably insecure, so it is unsuitable for production.

See How to deploy static files for proper strategies to serve static files in production environments.