我在模板中的变量是:{% with lang=request.session.lang %}
并保存“en”或“ua”
在 <li>
我检查当前 url 是否等于/lang/:
<li class="{% ifequal request.path '/lang/'%} active {% endifequal%}">
但是它不起作用。我 99% 确定问题出在它身上:'/lang/'
解析 ifequal
中的变量的正确方法是什么标签和引号
最佳答案
您可以在此处再使用一个 with
并使用 add
构建路径:
{% with "/"|add:lang|add:"/" as path %}
<li class="{% ifequal request.path path %} active {% endifequal%}">
{% endwith %}
关于django - 在模板标签的引号中插入变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27476824/