arm93
arm93

Reputation: 129

Django - 404 static files not found

I know theres about a millon of these questions but non of them have helped me out.

I can't access my static files for deployment, I've slpit my settings file into base and production and put them in a folder in the settings.py orginal file.

I've done everything neccessary but it still doesn't seem to be working and I can't work it out for the life of me.

I've tried editing the path several time and no change.

Maybe I've missed something obvious and someone else can see it.

  1. venv
  2. --project
  3. ----app1
  4. ------static folder
  5. ----wsgi folder
  6. ------settings_old.py
  7. ------new settings folder
  8. ---------base.py
  9. ---------production.py

base.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = ['django.contrib.staticfiles',]

STATIC_URL = '/static/'

STATIC_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'static_r')

STATICFILES_FINDERS = ( 
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

I've tried a couple of different things like changing from BASE_DIR to a new PROD_DIR that directly goes to the static file in index.

PROD_ROOT = os.path.dirname(os.path.abspath('__file__' ))
PROD_ROOT= os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath('__file__' ))))
PROD_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

Nothing seems to be working.

UPDATE:

as suggested by other I've tried collectstatic, the folder env/project/static_r was found however, i get

'0 files where copied to static_r'.

furthermore, also as suggested I printed out base_dir and prod_dir and got the following

"prod is /user/venv/project" & "base is /user/venv/project/wsgi-folder"

p.s this is after I edited prod_dir to -

PROD_ROOT = os.path.dirname(os.path.abspath('__file__' ))

Upvotes: 0

Views: 579

Answers (3)

droidv
droidv

Reputation: 888

I am not really sure, but are you sure it is STATIC_DIRS and not STATICFILES_DIRS? '-'

Upvotes: 1

Borko Kovacev
Borko Kovacev

Reputation: 1020

What you can always do to test your paths is to print it.

so in your settings do

print BASE_DIR, STATIC_DIRS, STATIC_ROOT

and you'll see where your error is.

In my opinion it's the fact you're putting the static folder within the app, rather than within the project, because collectstatic will put all static files in one directory regardless

Upvotes: 0

BHa
BHa

Reputation: 68

Based on your settings, your static files should be located in /project/static/ instead of in the individual app.

You will also need to load the static files as stated in the documentation

{% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image"/>

Upvotes: 0

Related Questions