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)
评论列表
文章目录