0

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.

2 Answers2

0

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')
  • 1
    You forget that originally you had a _leading_ slash in your path, the backslash and slash don't really matter if you use the function properly. – Abdul Aziz Barkat Oct 06 '21 at 10:30
  • `STATIC_ROOT = os.path.join(BASE_DIR,'\vol\web\staticfiles')` give this output:F:\7.Django\BLOG_PROJECT\src_blog\

    ol\web\staticfiles any way I edited my answer above: ol\web\staticfiles
    – Trọng Nhân Oct 06 '21 at 10:57
0

It probably solve your problem.

STATIC_ROOT = BASE_DIR / 'path'
deVOID
  • 155
  • 7