靜態文件,常用在head中,可動態的去檢索settings里面的STATIC_URL = '/static/',然后做拼接
settings.py中
STATIC_URL = '/static9/' # 9只是為了方便說明問題
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static2'),
os.path.join(BASE_DIR,'static0'),
os.path.join(BASE_DIR,'static1'),
]
html.py中
{% load static %} # 常放在html標簽的第一行
{% get_static_prefix %} >>> /static9/
<link href="{% static '/css/bootstrap.css' %}">
>>> '/static9/css/bootstrap.css' 自動做拼接
>>> 查找'css/bootstrap.css'這個文件
>>> 查找順序是按照添加路徑的先后,也就是 2 -> 0 -> 1