0

In my settings.py mention:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

My folder structure

project_name
   static
     bootstrap
   settings
      settings.py

I am not able to access the static files. Though If I add STATIC_DIRS( and comment STATIC_ROOT) as below I can access the static files.

STATICFILES_DIRS = (
     os.path.join(BASE_DIR, "static"),
)
Coderaemon
  • 3,619
  • 6
  • 27
  • 50

1 Answers1

4

There is a difference between static root and staticfiles dirs

STATICFILES_DIRS tells django where to look for the static files apart from the standard app directories.

STATIC_ROOT tells where to collect all the static files on using the collectstatic command.

You need to set STATIC_ROOT to some other path from where your webserver (nginx) can server them directly in production.

utkbansal
  • 2,787
  • 2
  • 26
  • 47
  • 2
    For more info, take a look here: http://stackoverflow.com/questions/24022558/differences-between-staticfiles-dir-static-root-and-media-root – Ryan Dec 14 '15 at 12:31
  • So both STATIC_DIRS and STATIC_ROOT both I have to define ? – Coderaemon Dec 14 '15 at 12:38
  • Yes you need both. But during development only staticfiles_dirs will do. – utkbansal Dec 14 '15 at 12:38
  • I don't know but only when I comment STATIC_ROOT can I access the static files. Is there any order of defining these variables? – Coderaemon Dec 14 '15 at 12:44
  • You need to set STATIC_ROOT to some other directory. STATIC_ROOT and STATICFIELS_DIRS should not point to the same directories. There is no fixed order for defining them – utkbansal Dec 14 '15 at 12:45