这样写可不可以,是不是更快一点?
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,
})