def main_news request page page int page paginator Paginator News obje

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def main_news(request, page=1):
page = int(page)
paginator = Paginator(News.objects.select_related().order_by('-pub_date'), 20)
pages = paginator.page_range
try:
page_ = paginator.page(page)
page_news = page_.object_list
except InvalidPage:
raise Http404
return render_to_response('main.html', {
'Main_news': page_news,
'page_range': paginator.page_range,
'has_next': page_.has_next(),
'has_previous': page_.has_previous(),
'has_other_pages': page_.has_other_pages(),
'current_page' : page,
'previous_page': page - 1,
'next_page': page + 1,
'url': '/news/page',
},
context_instance=RequestContext(request)
)