views.py 文件源码

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

项目:DTV 作者: Airwavess 项目源码 文件源码
def index(request):
    template = get_template('index.html')

    attractions_data = Attractions.objects.all()
    paginator = Paginator(attractions_data, 5) # Show 10 content per page
    page = request.GET.get('page')

    try:
        content = paginator.page(page)
    except PageNotAnInteger:
    # If page is not an integer, deliver first page.
        content = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        content = paginator.page(paginator.num_pages)

    index = content.number
    max_index = len(paginator.page_range)
    start_index = max_index - 7 if index >= max_index - 5 else index - 1 if index != 1 else 1
    end_index = max_index + 1 if index >= max_index - 6 else index + 7 if index != 1 else index + 8
    page_range = range(start_index, end_index)

    html = template.render(locals())
    return HttpResponse(html)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号