📂django
🔖搜索
2022-09-13 16:12阅读: 26评论: 0推荐: 0

列表搜索

后端

from django.db.models import Q
def user_list(request):
    if request.method == 'GET':
        keywords = request.GET.get('keywords').strip()
        con = Q()
        if keywords:
            con.connector = 'OR'
            con.children.append(('username__contains', keywords))
            con.children.append(('mobile__contains', keywords))
        queryset = User.objects.filter(con).filter(isAdmin=0).select_related('level')
        return render(request, 'user/list.html',
                      {'users': queryset,'keywords': keywords})

前端

<form class="form-inline" method="get">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="输入关键字" name="keywords" value="{{ keywords }}">
                </div>
       <button type="submit" class="btn btn-default">搜索</button>
</form>

本文作者:Sherwin

本文链接:https://www.cnblogs.com/sherwin1995/p/16689514.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Sherwin_szw  阅读(26)  评论(0编辑  收藏  举报
(评论功能已被禁用)
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.