views.py 文件源码

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

项目:instagram_miner 作者: allardbrain 项目源码 文件源码
def campaign_detail(request, pk):
    ''' Renders a template showing the photo results of the campaign. 20 results per page,
    with pagination capabilities at the bottom of each page.''' 

    campaign = get_object_or_404(Campaign, pk=pk)

    # Query the DB to find all Photo records associated with this campaign
    results = Photo.objects.filter(campaign_number=pk)

    # Set up the pagination of the results
    paginator = Paginator(results, 20) # Show 20 contacts per page
    page = request.GET.get('page')

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

    return render(request, 'ig_miner_app/campaign_detail.html', {'campaign': campaign,
                                                                'results':results,
                                                                'page_content': page_content})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号