1
색인 또는 annoucements 페이지로 이동하면 embed_text에 'index'또는 'announcements'page_name을 각각 보내고 있습니다. navbar의 현재 링크에 활성 클래스를 설정해야합니다. As shown in the picture (movies is my index page)매번 Django 템플릿이 참을 반환합니다.
는 그것은 index.html을 템플릿
{% if embed_text.page_name == 'index' %}
{% block movies_active %}active{% endblock %}
{% endif %}
{% if embed_text.page_name == 'announcements' %}
{% block announcements_active %}active{% endblock %}
{% endif %}
에 내 코드입니다 그리고 그것은 모두마다
<li class="{% block movies_active %}{% endblock %}"><a href="{% url 'movies:index' %}"> Movies</a></li>
<li class="{% block announcements_active %}{% endblock %}"><a href="{% url 'movies:announcements' %}"> Announcemets</a></li>
그래서 index.html을에 확장 base.html 템플릿 코드 표현식은 True를 반환하고 두 링크를 모두 활성화로 설정하면 그림에서 볼 수 있습니다. 나는 약간의 세부 사항을 놓치고있다. 제발, 도와주세요.
이제 작동합니다. 감사 – Ujinjinjin