我学习Python,做测试项目。你知道吗
大小写:我需要根据页面url为<li>
使用class="active"
。现在我使用django.core.context_processors.request
从path
获取url。你知道吗
现在的样子:
<li role="presentation" {% if request.path == '/' %}class="active"{% endif %}><a href="{% url 'home' %}">Home</a></li>
<li role="presentation" {% if '/groups' in request.path %}class="active"{% endif %}><a href="{% url 'groups' %}">Groups</a></li>
所以,如果我打开主页-first<li>
是活动的,如果url包含"/groups"
-secon<li>
是活动的。它可以工作,但我想做得更复杂,比较url和url.patterns
中的urls.py
:
url(r'^$', 'students.views.students_list', name='home'),
url(r'^groups/$', 'students.views.groups_list', name='groups')
问题:怎么做?由于语法错误,我不能在if
-语句中使用{% url 'groups' %}
。我需要一些建议。你知道吗
您可以将url标记的结果分配给变量。你知道吗
相关问题 更多 >
编程相关推荐