本文整理汇总了Python中django.core.paginator.ObjectPaginator.page方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectPaginator.page方法的具体用法?Python ObjectPaginator.page怎么用?Python ObjectPaginator.page使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.paginator.ObjectPaginator
的用法示例。
在下文中一共展示了ObjectPaginator.page方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import page [as 别名]
def home(request):
""" Home Page """
pager = ObjectPaginator(Post.objects.all(), 10)
pager.page = int(request.GET.get("sayfa", 1))
try:
posts = pager.get_page(pager.page - 1)
except:
posts = None
pager.url = make_url_pattern(reverse("home"), request.GET)
return render_to_response("entries/home.html", {
"posts" : posts,
"pager" : pager
}, context_instance=RequestContext(request))
示例2: category_detail
# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import page [as 别名]
def category_detail(request, slug):
""" Category detail page """
category = get_object_or_404(Category.objects, slug=slug)
pager = ObjectPaginator(Post.objects.filter(category=category), 10)
pager.page = int(request.GET.get("sayfa", 1))
try:
posts = pager.get_page(pager.page - 1)
except:
posts = None
pager.url = make_url_pattern(reverse("category_detail", kwargs={"slug": slug}), request.GET)
return render_to_response("entries/category_detail.html", {
"category" : category,
"posts" : posts,
"pager" : pager
}, context_instance=RequestContext(request))