Also, Django won’t serve static when in production. If you need to serve static files, then you will need to either host them somewhere like AWS or your own webserver, or use a third party package like whitenoise. Check it out here: https://whitenoise.evans.io/en/stable/django.html
Lastly, you will need to give Django a URL from which to serve static files, for example,
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I have this same problem. Admin area doesn’t load css style. Also, my app does not load css styles.
I have read everything and followed all processes available on the internet, but its still not working.
I really need help at this point. I can’t think of any solution.
Please help me resolve this issue.
There is not really enough data to diagnose your problem.
It would help to see the output of the Network tab on the Chrome DevTools as the page loads. I suspect that your site is returning 404 errors for the CSS and JavaScript files.
Here are some questions to answer:
How are you running Django? Are you using ./manage.py runserver or some other Python webserver?
Is DEBUG set to True or False in your settings.py?
Did you run ./manage.py collectstatic as recommended earlier in the thread?
The screenshot you shared is from your actual application rather than the admin. We can see from the network tab that the static assets like boostrap.min.css are loading (and that the page contains some bootstrap styles). Can you share a similar screenshot from the /admin/login/ page where the static assets do not appear to be loading?
Also, can you list what you have in INSTALLED_APPS in your settings file?
By the way, for sharing code on the forum, instead of using a screenshot, you can use the backtick (`) character when you put in code. This is sometimes called “fenced code” because 3 backtick characters are used above and below the code and make something that seems like a fence (note: not apostrophe characters!).
@ogbodotg The CSS files seemed to work fine after I cleared my cache and hit reload a few times. Is there a reason for this type of behavior or is there something wrong with the way I am working with static files.
What you can do is use either shift-reload or shift-F5 to force files to be loaded. You can also look at your console output where the requests are being served. If you see a 200 response code that means the files were loaded, but if you get a 304 response, that means that it found the file in cache and is using the cached version.
You could configure your app to disable caching, that can help when you’re doing a lot of work with your CSS.