文章内容页信息和标签调用方法
views.py
def art(request, tail):
if request.method == 'GET':
art = Art.objects.get(art_tail=tail)
# 相关信息
arts = Art.objects.filter(Q(art_title__icontains=art.art_keyword) | Q(art_keyword__icontains=art.art_keyword) | Q(art_title__icontains=art.art_keyword))[:8]
videos = Video.objects.all()[:3]
# 侧边栏
tags = Side.side_tags
new_arts = Side.side_new_arts
hot_arts = Side.side_hot_arts
context = {'art': art, 'arts': arts, 'videos': videos, 'tags': tags, 'new_arts': new_arts, 'hot_arts': hot_arts}
return render(request, 'art.html', context=context)
art.html
<article class="content">
<header class="article_header">
<h1>{{ art.art_title }}</h1>
<div class="article_meta">
<span class="item">日期:{{ art.art_time }}</span>
<span class="item">栏目:<a href="/artlist-{{ art.art_top_list.art_list_tail }}/" title="{{ art.art_top_list.art_list_title }}">{{ art.art_top_list.art_list_short_title }}</a></span>
<span class="item">阅读:{{ art.art_click }}</span>
<span class="item">作者:{{ art.art_author }}</span>
</div>
</header>
<div class="texts">
{{ art.art_text|safe }}
</div>
</article>