def article_list(request,block_id): block_id=int(block_id) block = Block.objects.get(id=block_id) articles=Article.objects.filter(block=block).order_by("last_update_timestamp") page_no = int(request.GET.get("page_no", "1")) (object_list, pagination_data) = paginate_queryset(articles,page_no,cnt_per_page=1) return render_to_response("article_list.html", {"articles": object_list, "b": block, "pagination": pagination_data}, context_instance=RequestContext(request))
def article_detail(request, article_id): article_id = int(article_id) article = Article.objects.get(id=article_id) page_no = int(request.GET.get("comment_page_no", "1")) comments = Comment.objects.filter(article=article, status=0) comments, pagination_data = paginate_queryset(comments, page_no, cnt_per_page=5) return render_to_response("article_detail.html", {"buluojianshe": article.block, "article": article, "comments": comments, "pagination": pagination_data}, context_instance=RequestContext(request))
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) page_no = int(self.request.GET.get("page_no", "1")) all_comments = Comment.normal_objects.filter(article=context["article"]) comments, pagination_data = paginate_queryset(all_comments, page_no, cnt_per_page=3) context['comments'] = comments context['pagination_data'] = pagination_data return context
def article_list(request, block_id): block_id = int(block_id) block = Block.objects.get(id=block_id) page_no = int(request.GET.get("page_no", "1")) all_articles = Article.objects.filter(block=block, status=0).order_by("-id") page_articles, pagination_data = paginate_queryset(all_articles, page_no) return render(request, "article_list.html", {"articles": page_articles, "b": block, "pagination_data": pagination_data})
def index(request): post_list = Post.objects.all().order_by("-id") page_no = int(request.GET.get("page_no", "1")) page_articles, pagination_data = paginate_queryset(post_list, page_no) return render(request, 'blog/index.html', context={ 'post_list': page_articles, 'pagination_data': pagination_data })
def tags(request, pk): label = get_object_or_404(Tag, pk=pk) post_list = Post.objects.filter(tags=label).order_by("-id") page_no = int(request.GET.get("page_no", "1")) page_articles, pagination_data = paginate_queryset(post_list, page_no) return render(request, "blog/index.html", context={ "post_list": page_articles, "pagination_data": pagination_data })
def category(request, pk): cate = get_object_or_404(Category, pk=pk) post_list = Post.objects.filter(category=cate).order_by("id") page_no = int(request.GET.get("page_no", "1")) page_articles, pagination_data = paginate_queryset(post_list, page_no) return render(request, "blog/index.html", context={ "post_list": page_articles, "pagination_data": pagination_data })
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) page_no = int(self.request.GET.get("page_no", "1")) all_comments = Comment.normal_objects.filter( article=context["article"]) comments, pagination_data = paginate_queryset(all_comments, page_no, cnt_per_page=3) context['comments'] = comments context['pagination_data'] = pagination_data return context
def index(request): page_no = int(request.GET.get("page_no", "1")) blocks = Blocks.objects.all().order_by("id") articles = Articles.objects.all().order_by("-id") articles_objs, pagination_data = paginate_queryset(articles, page_no) return render( request, "index.html", { "blocks": blocks, "articles": articles_objs, "pagination_data": pagination_data })
def article_list(request,block_id): block_id = int(block_id) page_no = int(request.GET.get('page_no','1')) block = Block.objects.get(id=block_id) articles = Article.objects.filter(block=block).order_by("-last_update_timestamp") (article_lists,pagination_data) = paginate_queryset(articles,page_no,cnt_per_page=2,half_show_length=5) return render_to_response("article_list.html", {"articles":article_lists, "b":block, 'pagination':pagination_data}, context_instance=RequestContext(request))
def article_list(request, block_id): block_id = int(block_id) block = Block.objects.get(id=block_id) page_no = int(request.GET.get("page_no", "1")) all_articles = Article.objects.filter(block=block, status=0).order_by("-id") page_articles, pagination_data = paginate_queryset(all_articles, page_no) return render(request, "article_list.html", { "articles": page_articles, "b": block, "pagination_data": pagination_data })
def ariticle_detail(request,article_id): article_id = int(article_id) article = Article.objects.get(id=article_id) profile_art = UserProfile.objects.get(owner=article.owner) comment_page_no = int(request.GET.get('comment_page_no','1')) comments = Comment.objects.filter(article=article) (comment_lists,pagination_data) = paginate_queryset(comments,comment_page_no,cnt_per_page=2,half_show_length=5) return render_to_response("article_detail.html", {"comments":comment_lists, 'article':article, 'pagination':pagination_data, 'profile_art':profile_art}, context_instance=RequestContext(request))
def article_list(request, block_id): block_id = int(block_id) blocks = Block.objects.get(id=block_id) page_no = int(request.GET.get('page_no', '1')) all_articles = Article.objects.filter(block=blocks, status=0).order_by('-id') page_articles, pagination_data = paginate_queryset(all_articles, page_no) return render( request, 'article_list.html', { 'blocks': blocks, 'articles': page_articles, 'pagination_data': pagination_data })
def article_list(request, block_id): block_id = int(block_id) page_no = int(request.GET.get("page_no", "1")) block = Block.objects.get(id=block_id) articles = Article.objects.filter(block=block).order_by("-last_update_timestamp") articles_object_list, pagination = paginate_queryset(articles, page_no, cnt_per_page=2) return render_to_response("article_list.html", {'blo': block, 'articles': articles_object_list, 'pagination': pagination}, context_instance=RequestContext(request))
def article_detail(request, article_id): page_no = int(request.GET.get("comment_page_no", "1")) article_id = int(article_id) article = Article.objects.get(id=article_id) comments = Comment.objects.filter(article=article, status=0) comments, pagination_data = paginate_queryset(comments, page_no, cnt_per_page=3) return render_to_response("article_detail.html", { "article": article, "comments": comments, "pagination": pagination_data }, context_instance=RequestContext(request))
def articles_list(request, block_id): page_no = int(request.GET.get("page_no", "1")) block_id = int(block_id) blocks = Blocks.objects.all() block = Blocks.objects.get(id=block_id) articles = Articles.objects.filter(block=block).order_by("-id") articles_objs, pagination_data = paginate_queryset(articles, page_no) return render( request, "articles_list.html", { "block_id": block_id, "blocks": blocks, "articles": articles_objs, "pagination_data": pagination_data })
def article_detail(request, article_id): article_id = int(article_id) articles = Article.objects.get(id=article_id) block = articles.block comment_page_no = int(request.GET.get("comment_page_no", "1")) comments = Comment.objects.filter(article=articles).order_by("last_update_timestamp") comments_object_list, pagination = paginate_queryset(comments, comment_page_no, cnt_per_page=6) return render_to_response("article_detail.html", {'articles': articles, 'blo': block, 'article_id': article_id, 'pagination': pagination, 'comments': comments_object_list}, context_instance=RequestContext(request))
def article_list(request, block_id): block_id = int(block_id) block = Block.objects.get(id=block_id) articles = Article.objects.filter( block=block).order_by("last_update_timestamp") page_no = int(request.GET.get("page_no", "1")) (object_list, pagination_data) = paginate_queryset(articles, page_no, cnt_per_page=1) return render_to_response("article_list.html", { "articles": object_list, "b": block, "pagination": pagination_data }, context_instance=RequestContext(request))
def article_list(request, block_id): """ :param request: Django帮我们包装好的请求应用的对象 :param block_id: urls.py里面匹配后赋值的变量,本身为字符串型,所以查询的时候需要先转换成整型 """ block_id = int(block_id) # 这里可以放心的使用int()函数转换,因为在urls.py里的正则表达式匹配的是数字,只不过是以字符串类型储存 block = Block.objects.get(id=block_id) articles = Article.objects.filter(block=block).order_by("-last_update_timestamp") # 使用分页函数计算文章列表 page_num = int(request.GET.get("page_num", "1")) # 获取前端传进来的页面参数,如果没有获取到任何值,默认值为1 page_list, pagination_data = paginate_queryset(articles, page_num, current_pages=1, half_page_links=5) return render_to_response("article_list.html", {"articles": page_list, "blk": block, "pagination": pagination_data}, context_instance=RequestContext(request))
def article_list(request,block_id): block_id = int(block_id) page_no = int(request.GET.get("page_no", "1")) block = Block.objects.get(id=block_id) articles = Article.objects.filter(block=block).order_by("-last_update_timestamp") # p=Paginator(articles,1) # if page_no > p.num_pages: # page_no = p.num_pages # if page_no <= 0: # page_no = 1 # page_links=[i for i in range(page_no-5,page_no+6) if i > 0 and i < p.num_pages] # page=p.page(page_no) # previous_link=page_links[0]-1 # next_link=page_links[-1]+1 # return render_to_response("article_list.html", {"articles":page.object_list,"b":block,"has_previous":previous_link > 0,"has_next":next_link <= p.num_pages,"previous_link":previous_link,"next_link":next_link,"page_cnt":p.num_pages,"current_no":page_no,"page_links":page_links},context_instance=RequestContext(request)) object_list, pagination_data = paginate_queryset(articles, page_no, cnt_per_page=1) return render_to_response("article_list.html", {"articles":object_list, "b":block, "pagination":pagination_data}, context_instance=RequestContext(request))