慕运维9272330
2019-07-31 16:57
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,
})
哈哈,可以的
如果中间有些文章被删掉导致id不连续该怎么解决呢
三小时带你入门Django框架 新版上架
25588 学习 · 248 问题
相似问题