0
我在我的視圖中使用了get_next_by_FOO來顯示一組記錄中下列項目的絕對URL,但是當它到達查詢集的末尾時會引發錯誤。如何在django視圖中限制get_next_by_FOO?包括的代碼
我該如何阻止我的觀點提出這個錯誤,而只是輸出一些HTML讓我知道它已經到了集合的末尾?
非常感謝所有幫助。
這是錯誤消息,我的視圖和模板代碼。
錯誤
Exception Type: DoesNotExist
Exception Value: Body matching query does not exist.
查看
def news_view(request, url):
news = get_object_or_404(Body, url=url)
next = news.get_next_by_published()
pre = news.get_previous_by_published()
return render_to_response('news/news_view.html', {
'news': news,
'pre': pre,
'next': next
}, context_instance=RequestContext(request))
模板
<a href="{{ next.get_absolute_url }}">Next News</a></p>
<a href="{{ pre.get_absolute_url }}">Previous News</a></p>