page页面侧边栏当前页面高亮显示
views.py
def page(request, tail):
if request.method == 'GET':
page = Page.objects.get(page_tail=tail)
pages = Page.objects.all()
url = request.path # /page-about.html
str = url.split('.', 1)[0].split('-', 1)[1] # about
context = {'page': page, 'pages': pages, 'str': str}
return render(request, 'page.html', context=context)
page.html
<!-- 中间部分 start -->
<div class="container">
<div class="main_center clearfix">
<aside class="page_aside fl">
<a href="">
<img class="page_ad" src="page_files/cfcd208495d565e-17.jpg" alt="">
</a>
<ul class="page_item">
{% for p in pages %}
{% if p.page_tail == str %}
<li style="background-color:red;"><a href="/page-{{ p.page_tail }}.html">{{ p.page_title }}</a></li>
{% else %}
<li><a href="/page-{{ p.page_tail }}.html">{{ p.page_title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</aside>
<div class="page_content fr">
<header class="page_header">
<h1 class="page_h1">{{ page.page_title }}</h1>
</header>
<article class="page_article">
{{ page.page_text|safe }}
</article>
</div>
</div>
</div>
<!-- 主体内容 -->