若在某個項目中修改了靜態文件的別名,則需要進行修改一系列引用該別名的路徑,如:
則需要對每個引用該路徑的別名進行修改,如:
這種方式繁瑣,因此我們使用load static 加載靜態文件別名,
方式一:系統自動進行拼接:
{% load static%} 加載靜態路徑別名
href="{%static '路徑'%}" 系統自動進行拼接
{% load static%} 加載靜態路徑別名
{%static '路徑' as 變量名%} 系統自動進行拼接,並將路徑賦值給某個變量
href=“{{變量名}}” 通過變量名引用路徑
方式二:自己進行拼接:
{%load static%} 加載靜態路徑別名
href="{%get_static_prefix%} 路徑" 自己進行拼接
或者
{%load static%} 加載靜態路徑別名
{%get_static_prefix as static_prefix%} 將路徑別名賦值給變量
href="{{static_prefix}} 路徑" 通過變量進行路徑的拼接