Home > Software design >  Django: STATIC_ROOT STATIC_ROOT can't join with BASE_DIR path
Django: STATIC_ROOT STATIC_ROOT can't join with BASE_DIR path

Time:10-07

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

I set up my STATIC_ROOT like this

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:

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. Sure! It set my STATIC_ROOT AT F:/vol/web/staticfiles. I noticed that it print out the separate folder symbol different '/' and #backslashsymbol. I use windows os btw.

CodePudding user response:

Solved it! Just change it to a backlash-symbol instead of '/'.
Look like just a window vs linux anoying thing.

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 :
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(BASE_DIR, 'vol', 'web', 'staticfiles')

CodePudding user response:

It probably solve your problem.

STATIC_ROOT = BASE_DIR / 'path'
  • Related