def index(request): # list of news articles context = { 'list_blogs': Blog.get_latest_blogs()[:5], 'list_news': PressRelease.get_latest_news()[:4], 'view_index': True, 'active_page': "index", } return render(request, 'blog/index.html', context)
def blog(request): """ Using paginator to view list of blog posts """ # list of all blog entries blog_list_all = Blog.get_latest_blogs() paginator = Paginator(blog_list_all, 5) # show 5 blogs per page page = request.GET.get('page') try: blogs = paginator.page(page) except PageNotAnInteger: # if page is not an integer, deliver first page blogs = paginator.page(1) except EmptyPage: # if page is out of range, deliver last page of results blogs = paginator.page(paginator.num_pages) context = { 'list_blogs': Blog.get_latest_blogs()[:5], 'view_index': False, 'main_list': blogs, 'active_page': "blog", } return render(request, 'blog/blog.html', context)
def blog_detail(request, blog_id, slug): # retrieve blog of interest article_of_interest = get_object_or_404(Blog, pk=blog_id) context = { 'current_blog': article_of_interest, 'list_blogs': Blog.get_latest_blogs()[:5], 'view_index': False, 'view_blog_entry': True, 'active_page': "blog", } return render(request, 'blog/blog-detailed.html', context)