Exemple #1
0
def search(request):
    ss = request.GET.get('search')
    list = Article.objects.filter(title__icontains=ss)
    remen = Article.objects.filter(tui__id=2)[:6]
    allcategory = Category.objects.all()
    tags = Tag.objects.all()
    # 分页操作
    page = request.GET.get('page')  # url中获取当前页码
    paginator = Paginator(list, 2)  # 对查询到的数据进行分页,一页显示5条
    try:
        list = paginator.page(page)  # 获取当前页码的数据
    except PageNotAnInteger:
        list = paginator.page(1)  # 如果用户输入的页码不是整数,显示第一页
    except EmptyPage:
        list = paginator.page(paginator.num_pages)  # 如果输入的页码不在页码列表中,显示最后一页
    return render(request, 'search.html', locals())
Exemple #2
0
def tag(request, tag):
    list = Article.objects.filter(tags__name=tag)
    tname = Tag.objects.get(name=tag)
    remen = Article.objects.filter(tui__id=2)[:6]
    allcategory = Category.objects.all()
    tags = Tag.objects.all()
    # 分页操作
    page = request.GET.get('page')  # url中获取当前页码
    paginator = Paginator(list, 2)  # 对查询到的数据进行分页,一页显示5条
    try:
        list = paginator.page(page)  # 获取当前页码的数据
    except PageNotAnInteger:
        list = paginator.page(1)  # 如果用户输入的页码不是整数,显示第一页
    except EmptyPage:
        list = paginator.page(paginator.num_pages)  # 如果输入的页码不在页码列表中,显示最后一页
    return render(request, 'tags.html', locals())