Answer the question
In order to leave comments, you need to log in
How to customize navigation in Django via url.patterns?
Good evening.
I'm learning Python, doing a test project.
Task: to make sure that for is assigned based on the page address. I implement via to pull the address from .
Here's what it looks like now:class="active"
<li>
django.core.context_processors.request
path
<li role="presentation" {% if request.path == '/' %}class="active"{% endif %}><a href="{% url 'home' %}">Главная</a></li>
<li role="presentation" {% if '/groups' in request.path %}class="active"{% endif %}><a href="{% url 'groups' %}">Группы</a></li>
url(r'^$', 'students.views.students_list', name='home'),
url(r'^groups/$', 'students.views.groups_list', name='groups')
{% url 'groups' %}
if
Answer the question
In order to leave comments, you need to log in
There are three levels for solving such problems
0. Model. in the method you do the whole kitchen - the result is in the form of a dict. The downside is that it’s not always convenient to receive request
1. View, the same thing, only request is convenient to receive
2. Template, a template tag is written and magic happens inside it
In the test, you better do everything in the view in a separate function
If the menu is simple without problems and there are not so many elements in it, then I usually reserve a block for each element and then in the right template I just write a class in this block, not a lot of dirty implementation but simple, for example:
<li class="{% block home %}{% endblock %} treeview">
<a href="/">
<i class="fa fa-rocket"></i>
<span>Главная</span>
</a>
</li>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question