文章内容页翻页和点击统计开发
views.py
def art(request, tail):
if request.method == 'GET':
art = Art.objects.get(art_tail=tail)
# 翻页 01234
previous_page = Art.objects.filter(id__gt=art.id).first()
next_page = Art.objects.filter(id__lt=art.id).first()
# 点击
art.art_click += 1
art.save()
# 相关信息
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, 'previous_page': previous_page, 'next_page': next_page, 'arts': arts, 'videos': videos, 'tags': tags, 'new_arts': new_arts, 'hot_arts': hot_arts}
return render(request, 'art.html', context=context)
art.html
<div class="article_nav">
<div class="next">
{% if next_page %}
<span>| 下一篇:</span><a href="/art-{{ next_page.art_tail }}.html">{{ next_page.art_title }}</a>
{% else %}
| 没有了
{% endif %}
</div>
<div class="back">
{% if previous_page %}
<span>| 上一篇:</span><a href="/art-{{ previous_page.art_tail }}.html">{{ previous_page.art_title }}</a>
{% else %}
| 没有了
{% endif %}
</div>
</div>