Search code examples
pythondjangodjango-settings

Unable to join static file to root directory in Django


To join the static file in Django,

STATIC_URL = "os.path.join(BASE_DIR, '/static/')"

print("static file : ", (os.path.join(BASE_DIR, '/static')), )

This is producing :

static file :  C:/static

But in the same document I had joined template folder: print("Path is : ", os.path.join(BASE_DIR, 'myproject/template'))

Which produces this: Path is : C:\Users\user\Desktop\django\myproject\myproject/template

Is this the reason Django is producing this error:

ERRORS:
?: (urls.E006) The STATIC_URL setting must end with a slash.

Could you please advise how can i resolve this error?


Solution

  • STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
    

    STATIC_URL is the path on your website url.

    STATIC_ROOT is the path on your server where static files are located.