STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'
In my templates:
{% load static %}
<link href="{% static "main.css" %}" rel="stylesheet">
<link rel="shortcut icon" href="{% static "logo3.gif" %}" />
I stuck with that problem. Earlier in my Django simple project, all was ok. So my settings should be right.
Any help will be appreaciate. Or any idea how to check, in simple way, what is wrong with my static loading
With all the best
Ewa
Check STATICFILES_DIRS
Since you are running locally, you need to add:
python
CopyEdit
STATICFILES_DIRS = [BASE_DIR / "static"]
This tells Django where to look for static files in development mode.
2. Use runserver With --insecure (For Debugging)
Try running the development server with:
bash
CopyEdit
python manage.py runserver --insecure
This forces Django to serve static files even if DEBUG = False.
3. Check If Static Files Are Collected Properly
Run:
bash
CopyEdit
python manage.py collectstatic --noinput
Then check if all static files are correctly placed inside STATIC_ROOT.
4. Manually Serve Static Files (Development Mode Only)
If it's still not working, add this to urls.py (only for local testing!):
python
CopyEdit
from django.conf import settings
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
5. Check If Static Files Exist and Are Reachable
Run the following command to check what static files Django can find:
bash
CopyEdit
python manage.py findstatic main.css
If Django can't find the file, then it's not stored where it expects.
6. Confirm File Paths in Templates
Ensure your paths are correct. Try:
html
CopyEdit
<link href="{% static 'css/main.css' %}" rel="stylesheet">
If your main.css file is inside static/css/, then update your path accordingly.
7. Try Restarting the Server
Sometimes, simply stopping and restarting the Django server helps:
bash
CopyEdit
CTRL + C # Stop the server
python manage.py runserver # Start it again
8. Check Browser Dev Tools
Open your browser's Developer Console (F12) → Network → Static Files and check the request URL for errors.