def get_detail_page(request, article_id):
# print(article_id)
curr_article = Article.objects.get(article_id=article_id)
try:
previous_article = Article.objects.get(article_id=article_id-1)
except Exception as e:
previous_article = dict()
previous_article['article_id'] = article_id
previous_article['title'] = '没有了-.-'
try:
next_article = Article.objects.get(article_id=article_id+1)
except Exception as e:
next_article = dict()
next_article['article_id'] = article_id
next_article['title'] = '没有了-.-'
return render(request, 'blog/detail.html', {
'curr_article': curr_article,
'previous_article': previous_article,
'next_article': next_article,
})
哈哈,可以的
这个article_id不是数字顺序排列的吧,第一篇是id是3,第二篇可能就是5了。所以感觉还是下标更准确
如果中间有些文章被删掉导致id不连续该怎么解决呢