request的path是相对路径,所以可以根据访问路径的前几位来判断当前页,用法如下:
{%if request.path|slice:'7' == ‘/course’%} class="active"{% endif %}
使用django的template中的slice过滤器,使用路径的前六个字符
首页的匹配直接使用
{%if request.path == ‘/’%} class="active"{% endif %}
onlyhold 2017-11-25 11:52 原文
request的path是相对路径,所以可以根据访问路径的前几位来判断当前页,用法如下:
{%if request.path|slice:'7' == ‘/course’%} class="active"{% endif %}
使用django的template中的slice过滤器,使用路径的前六个字符
首页的匹配直接使用
{%if request.path == ‘/’%} class="active"{% endif %}