若在某个项目中修改了静态文件的别名,则需要进行修改一系列引用该别名的路径,如:
则需要对每个引用该路径的别名进行修改,如:
这种方式繁琐,因此我们使用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}} 路径" 通过变量进行路径的拼接