Static Root and Static Url confusion in Django

后端 未结 1 837
[愿得一人]
[愿得一人] 2021-01-02 22:39

I am trying to read create mp3 files in django. but I am confused about static and static_root that I have configured. WHat happening is that in my code at a point when I p

相关标签:
1条回答
  • 2021-01-02 23:18

    From the django docs,

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

    STATIC_URL is the URL to use when referring to static files located in STATIC_ROOT.

    So, when you request some specific static resource, it is searched in STATIC_ROOT + STATIC_URL and then served.

    Now in your problem, you do

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

    which means django would have effectively been searching in BASE_DIR/play/static_root/static/ which would be incorrect, so looking at other paths you can figure out that you need to do

    STATIC_ROOT = os.path.join(BASE_DIR, 'play/')
    
    0 讨论(0)
提交回复
热议问题