【发布时间】:2010-10-27 13:58:35
【问题描述】:
我在视图中使用 get_next_by_FOO 来显示一组记录中以下项目的绝对 url,但是当它到达查询集的末尾时会引发错误。
如何阻止我的视图引发此错误,而只是输出一些 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>
【问题讨论】:
标签: django django-templates django-views