简体   繁体   中英

Django Static files URL,ROOT,DIR confusion

I am using Django v1.11.In the setting file I have set like this

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "e","static","static_root")

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "e","static","static_dir"),
  ]

Firstly I copied all my css,js,img file in static_dir folder.Then I run the command

   python manage.py collectstatic

Which copied all the files from static_dir to static_root.As I can understand now all my css files should be loaded from static_root. But I can see that css files are being loaded from static_dir. So can anyone please explain it to me what is happening ? Why should I use static_root ? I can not find any use of static_root

The whole explanation can be found there

STATIC_ROOT provides a convenience management command for gathering static files in a single directory so you can serve them easily. When DEBUG is False , set a path to it before you use collectstatic

In addition to using a static/ directory inside your apps, you can define a list of directories ( STATICFILES_DIRS ) in your settings file where Django will also look for static files. For example:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    '/var/www/static/',
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM