django搜索

book/url.py

urlpatterns = [
    url(r'^hero_seach$', views.hero_seach, name="hero_seach"),
    ]

book/hero_seach.html




    

    book/views.py

    @check_user
    def hero_seach(request):
        hname = request.GET.get("hname")
        if hname:
            if hname=="":
                ret={"ret":[]}
                return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json;charset=utf-8")
            hname_list = HeroInfo.objects.filter(hname__icontains=hname).values("hname","id")
            info = []
            for i in hname_list:
                d={}
                d["hname"]=i["hname"]
                d["hid"]=i["id"]
                info.append(d)
            ret={"ret":info}
            return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json;charset=utf-8")
        return render(request, "book/hero_seach.html")

    你可能感兴趣的:(django搜索)