zoukankan      html  css  js  c++  java
  • django实现查询功能

    1.index首页显示

                        <div class="form-group pull-right" style="float: left">
                                <form action="" method="get">
                                    <input name="q" type="text" value="" class="form-control" placeholder="请输入搜索条件"  id="nav-search-input" style="display: inline-block; 200px;"><button class="btn btn-primary btn-search">
                                        <span class="glyphicon glyphicon-search"></span>
                                    </button></form>
                            </div>

    2.js的实现

            $('btn-search').click(function () {
                var keywords = $('#nav-search-input').val(),
                    request_url = '';
                if (keywords == '') {
                    return
                }
                request_url = '/index/?q=' +keywords;
                window.location.href = request_url
            });

    3.views视图

    def index(request):
        if not request.user.is_authenticated():
            return redirect('/login/')
        search_keywords = request.GET.get('q','')
        if search_keywords:
            product_list = Product.objects.filter(Q(product_keyword__contains=search_keywords)|Q(product_name__contains=search_keywords))
        else:
            product_list=Product.objects.all()
        paginator = Paginator(product_list,2)
        page_range = paginator.page_range
        num =request.GET.get('page',1)
        product_list = paginator.page(num)
        a = request.user
        return render(request, 'index.html', {"num":int(num),"page_range":page_range,"product_list":product_list,"a":a,'MEDIA_URL':settings.MEDIA_URL})

  • 相关阅读:
    获取与端点的连接
    判断div内滚动条是否在底部
    MVC的使用!
    格式转换解决存取数据安全问题
    JQuery input file 上传图片
    contenteditable 常用的一些CSS !!
    C# 生成Json类型数据
    生成Excel
    生成验证码
    图片水印
  • 原文地址:https://www.cnblogs.com/zhongbokun/p/9494840.html
Copyright © 2011-2022 走看看