Django STATIC_URL

in dango , the "STATIC_URL" is to manage the  url path of file

if the file is not in "STATIC_URL", then when django runs, browser is not link to the file alough it may has correct url link to local file.

 

for example:

the django project is like this:

 

mysite 

  ----static 

    ------myvue.vue

  ----template

    ------myvue2.vue

 

in setting.py 

STATIC_URL = "/static/"

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]

 

 

then when django runs, the url in browser is like this: https://127.0.0.1:8000/yourapp/

you can use two way to include myvue.vue in your index.html:

1. "{% static 'myvue.vue' %}"

2. "../static/myvue.vue"    this is a relative way which is based on the url---> https://127.0.0.1:8000/yourapp/, so the url to link file is now this: https://127.0.0.1:8000/static/myvue.vue

 

and you cannot access the myvue2.vue to your index.html, all because is that the link url is not in STATIC_URL, that is:

"../templates/myvue2.vue" cannot be included in your index.html  although the url link to file is correct.

 

 

and also you can know that when django runs, the "http://127.0.0.1:8000" represents that your current project environment which means that "mysite/"

 

posted @ 2018-08-04 10:47  aric.zhu  阅读(176)  评论(0编辑  收藏  举报