Hello everyone ,
I am having problem in using active class in django based on page opened when it is inside of inscription_detail page. Can anyone help me?
Note: below code shows active in inscription page but dont show in when we go inside the inscription_detail page. Here I want the page to be like this when we go to
inscriptions/
then in navbar inscription must be active and when we go to this page clicking the list in inscription
inscriptions/<int:year>/<int:month>/<int:day>/<slug:inscription>/
then also inscription in navbar must be active .
Here my navbar.html:
{% url 'core:inscription_list' as inscription_list%}
{% url 'core:inscription_detail' as inscription_detail%}
<li class="nav-item ">
<a class="nav-link {% if request.path == inscription_list %} active {% endif %} {% if request.path == inscription_detail %} active {% endif %}" href="{% url 'core:inscription_list' %}">inscriptions</a>
</li>
Here is urls.py:
path('inscriptions/', views.InscriptionListView.as_view(), name='inscription_list'),
path('inscriptions/<int:year>/<int:month>/<int:day>/<slug:inscription>/', views.inscription_detail,
name='inscription_detail'),
and views.py:
class InscriptionListView(ListView):
queryset = Inscription.published.all()
context_object_name = 'inscriptions'
template_name = 'core/inscription/inscriptions.html'
def inscription_detail(request, year, month, day, inscription):
inscription = get_object_or_404(Inscription, slug=inscription,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)
return render(request, 'core/inscription/inscriptions-detail-1.html', {'inscription': inscription})
views.py
navbar.html