Problem with static files inDjango-Oscar

116 views
Skip to first unread message

Szawunia

unread,
Mar 30, 2025, 3:44:32 PMMar 30
to Django users
Hi everybody,
I have problem with my static files in my Django project, running local. Actually Django-Oscar, but settings files is Django.  There are not founded (404 error). I have all my static files in my project directory (where 'manage.py' is).
My settings:

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


Faisal Tahseen

unread,
Mar 30, 2025, 4:08:50 PMMar 30
to Django users
If you Facing static file issue in your Django project.
You should use Base_Dir include OS

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'), 

Because you run the Project Locally.
I hope this will help you 

Abigaba Abraham

unread,
Mar 30, 2025, 4:08:56 PMMar 30
to Django users
Try installing Pillow if you didn't

Hugo Chavar

unread,
Mar 30, 2025, 4:09:00 PMMar 30
to Django users
Hi Ewa looks like you need one more setting for development:

STATICFILES_DIRS = [
    BASE_DIR / 'static_files',  # or whatever directory contains your static files
]

If that doesn't work, share your urls.py

Maybe it worked for a small project because you have DEBUG = False in that case.

Let me know if this worked!

Hugo

KEVIN DAVID

unread,
Mar 31, 2025, 10:05:56 AMMar 31
to Django users

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.

Aniket Raj Singh

unread,
Apr 4, 2025, 8:16:42 PMApr 4
to Django users
​When deploying a Django project with DEBUG = False, static files are not served automatically by Django. To handle static files in production, you can use WhiteNoise. After installing WhiteNoise, add 'whitenoise.middleware.WhiteNoiseMiddleware' to your MIDDLEWARE settings and set STATICFILES_STORAGE to 'whitenoise.storage.CompressedManifestStaticFilesStorage'. Then, run python manage.py collectstatic to collect all static files into the directory specified by STATIC_ROOT. This setup enables WhiteNoise to serve your static files efficiently in a production.
Reply all
Reply to author
Forward
0 new messages