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?
I encountered the same problem with my project. Here’s how you can resolve it:
First, add the STATIC_ROOT setting for static files in your settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
After that, run the following command to collect the static files:
python manage.py collectstatic
Finally, add a URL path to urlpatterns:
urlpatterns = [
path("admin/", admin.site.urls),
# your other paths here
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)