老师,关于static_root和staticfiles_dirs的区别

来源:3-2 配置表单页面

猿起猿灭

2018-06-10

我用static_root设置了静态文件路径,但是页面是没有找到这个文件,但是我用STATICFILES_DIRS这个就可以正常加载,请问,static_root要怎么用才有效?


写回答

3回答

不务正业的码农

2018-06-11

参考官方文档,回答下你的问题:

STATIC_ROOT is the folder where every static files will be stored after a manage.py collectstatic

The absolute path to the directory where collectstatic will collect static files for deployment.

If the staticfiles contrib app is enabled (default) the collectstatic management command will collect static files into this directory. See the howto on managing static files for more details about usage.

STATICFILES_DIRS is the list of folder where Django will search for additional static files, in addition to each static folder of each app installed.

This setting defines the additional locations the staticfiles app will traverse if the FileSystemFinder finder is enabled, e.g. if you use the collectstatic or findstaticmanagement command or use the static file serving view.


0
1
猿起猿灭
非常感谢!
2018-07-20
共1条回复

bobby

2018-06-12

static_root我会在部署章节中讲解到。楼下热心同学的答案你也可以看一下, static_root主要是部署中会用到,开发阶段不要设置这个变量

1
0

一事能狂便少年3312212

2018-09-29

不知道为什么我的项目之前跑不起来,提示我没有 STATIC_ROOT ,后来我自己加了一句 STATIC_ROOT = '/apps/', 奇迹般的好了....至今知道怎么回事....

0
1
一事能狂便少年3312212
刚才我把 STATIC_ROOT 删了也正常的...哎...算了...
2018-09-29
共1条回复

Python3.6+django+xadmin,打造在线教育平台

【毕设】Python 2.7到3.6 完美适配,Django升级2.0

3677 学习 · 4041 问题

查看课程