[Django]-Django 1.11 – static file not found

2👍

Since you are using customised path, why dont you tell the django where to find it.. use this in settings and it shall work fine.

option 1:

in case you are serious about preserving your file structure

#settings.py
STATICFILES_DIRS = (
    ...
    os.path.join(BASE_DIR, 'app/src/static') # build appropriate path
)

UPDATE:

option 2:

move the static folder to where manage.py exists or into the child of app.

example:

...manage.py
...static
...app/

or

...manage.py
...app/static

1👍

STATIC_URL only control the prefix of static files URL (i.e web address). It doesn’t control their physical location on disk.

Move your static files from app_name/src/static/ to app_name/static/ and that should fix it

Edit:
If you want to keep directory structure as it is, you have couple of options

  1. Manually add your static file directories to STATICFILES_DIRS
  2. Create a class that inherit from django.contrib.staticfiles.finders.AppDirectoriesFinder and set the source_dir attribute

from django.contrib.staticfiles.finders import AppDirectoriesFinder
class MyAppDirFinder(AppDirectoriesFinder):
source_dir = "src/static"

Then you can add your class to STATICFILES_FINDERS

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'myapp.finders.MyAppDirFinder',

]

Reference: https://docs.djangoproject.com/en/1.11/ref/settings/#static-files

👤Ramast

0👍

Indside static folder you need to create a folder with app name

Now your folder structure is

   |-------- src
    |------------ static
    |---------------- css
    |-------------------- bootstrap
    |------------------------ bootstrap.min.css

Change it to

|-------- src
|------------ static
|-------------------app_name
|--------------------------- css
|-------------------- ----------bootstrap
|---------------------------------------- bootstrap.min.css

0👍

add

STATICFILES_DIRS=(os.path.join(BASE_DIR, '../frontend'),)

or

STATICFILES_DIRS=()

in your settings.
Then it should work.
Took me a long time to find this.

Leave a comment