detail.html
<nav aria-label="..."> <ul class="pager"> {% if previous_article %} <li><a href="/blog/detail/{{previous_article.article_id}}">上一篇:{{previous_article.title}}</a></li> {% endif %} {% if next_article %} <li><a href="/blog/detail/{{next_article.article_id}}">下一篇:{{next_article.title}}</a></li> {% endif %} </ul> </nav>
views.py
def get_detail_page(request, article_id): curr_article = Article.objects.filter(article_id=article_id)[0] previous_article = Article.objects.filter(article_id__lt=article_id).last() next_article = Article.objects.filter(article_id__gt=article_id).first() section_list = curr_article.content.split('\n') return render(request, 'blog/detail.html', { 'curr_article': curr_article, 'section_list': section_list, 'previous_article': previous_article, 'next_article': next_article, })
这个可以,比视频里的更完善,视频里的完全是糊弄式代码