简体   繁体   English

Django:STATIC_ROOT STATIC_ROOT 无法加入 BASE_DIR 路径

[英]Django: STATIC_ROOT STATIC_ROOT can't join with BASE_DIR path

I want my STATIC_ROOT path to be at F:/7.Django/BLOG_PROJECT/src_blog/' + '/vol/web/staticfiles but django set it at F:/vol/web/staticfiles我希望我的 STATIC_ROOT 路径位于F:/7.Django/BLOG_PROJECT/src_blog/' + '/vol/web/staticfiles但 django 将其设置为F:/vol/web/staticfiles

I set up my STATIC_ROOT like this我这样设置我的 STATIC_ROOT

STATIC_ROOT = os.path.join(BASE_DIR,'/vol/web/staticfiles')

print('this is base_dir')
print(BASE_DIR)
print("this is static_root")
print(STATIC_ROOT) 

When I run python manage.py runserver it print out this:当我运行python manage.py runserver它打印出这个:

this is base_dir
F:\7.Django\BLOG_PROJECT\src_blog
this is static_root
F:/vol/web/staticfiles
this is base_dir
F:\7.Django\BLOG_PROJECT\src_blog
this is static_root
F:/vol/web/staticfiles

When I run python manage.py collectstatic .当我运行python manage.py collectstatic时。 Sure!当然! It set my STATIC_ROOT AT F:/vol/web/staticfiles .它将我的 STATIC_ROOT 设置为F:/vol/web/staticfiles I noticed that it print out the separate folder symbol different '/' and #backslashsymbol.我注意到它打印出不同的文件夹符号“/”和#backslashsymbol。 I use windows os btw.顺便说一句,我使用 windows 操作系统。

Solved it.解决了。 Just change it to a backlash-symbol instead of '/'.只需将其更改为反冲符号而不是“/”。
Look like just a window vs linux anoying thing.看起来就像 window 和 linux 一样烦人。

STATIC_ROOT = os.path.join(BASE_DIR,'vol\web\staticfiles')

edit: You know my answer above will create problem when you use your code in Linux base container @AbdulAzizBarkat give me a better solution:编辑:当你在 Linux 基本容器@AbdulAzizBarkat 中使用你的代码时,你知道我上面的回答会产生问题给我一个更好的解决方案:
You shouldn't be providing any slashes in your path if you want os.path.join to handle them properly, hence you should be writing如果您希望os.path.join正确处理它们,则不应在路径中提供任何斜杠,因此您应该编写

os.path.join(BASE_DIR, 'vol', 'web', 'staticfiles')

It probably solve your problem.它可能会解决您的问题。

STATIC_ROOT = BASE_DIR / 'path'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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