views.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:DjangoSpree 作者: prakharchoudhary 项目源码 文件源码
def image_list(request):
    images = Image.objects.all()
    paginator = Paginator(images, 8)
    page = request.GET.get('page')
    try:
        images = paginator.page(page)
        images_by_popularity = Image.objects.order_by('-total_likes')

    except PageNotAnInteger:
        if request.is_ajax():
            # If page is not an integer deliver the first page
            images = paginator.page(1)

    except EmptyPage:
        if request.is_ajax():
            # If the request AJAX and the page is out of range
            # return an empty page
            return HttpResponse('')
        # If page is out of range deliver last page of results
        images = paginator.page(paginator.num_pages)

    if request.is_ajax():
        return render(request, 'images/image/list_ajax.html',{'section': 'images', 'images': images})

    return render(request, 'images/image/list.html', {'section': 'images', 'images': images})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号