コード例 #1
0
ファイル: views.py プロジェクト: DayLink/tested
def categorypage(request, category_slug):
    category = get_object_or_404(Category, slug=category_slug)
    posts = Post.objects.filter(category=category)
    paginator = FlynsarmyPaginator(posts, 2, adjacent_pages=2) # Show 25 contacts per page
    page = request.GET.get('page')
    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        posts = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        posts = paginator.page(paginator.num_pages)
    return render_to_response('category.html', {'posts': posts, 'category': category}, context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: DayLink/tested
def mainpage(request):
    posts = Post.objects.all().order_by('-date')
    categories = Category.objects.all().order_by('-id')
    paginator = FlynsarmyPaginator(posts, 2, adjacent_pages=2) # Show 25 contacts per page
    page = request.GET.get('page')
    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        posts = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        posts = paginator.page(paginator.num_pages)

    return render_to_response('index.html', {'posts': posts, 'categories': categories}, context_instance=RequestContext(request))