实现搜索功能

李海力 李海力     2022-10-05     624

关键词:

  1. 准备视图函数search()

  2. 修改base.html 中搜索输入框所在的
    1. <form action="{{ url_for(‘search‘) }}" method="get">
    2.    <input name="q" type="text" placeholder="请输入关键字">

  3. 完成视图函数search()
    1. 获取搜索关键字
      q = request.args.get(‘q’)
    2. 条件查询
      qu = Question.query.filter(Question.title.contains(q)).order_by(‘-creat_time’)
    3. 加载查询结果:
      return render_template(‘index.html‘, question=qu)

  4. 组合条件查询
    from sqlalchemy import or_, and_ 

示例:

Lobby.query.filter(
    or_(
        and_(
            Lobby.id == Team.lobby_id,
            LobbyPlayer.team_id == Team.id,
            LobbyPlayer.player_id == player.steamid
        ),
         and_(
            Lobby.id == spectator_table.c.lobby_id,
            spectator_table.c.player_id == player.steamid
        )
    )
)

from sqlalchemy import or_,and_

 

@app.route(‘/search/‘)
def search():
    qu = request.args.get(‘q‘)
    ques = Question.query.filter(
        or_(
             Question.title.contains(qu),
             Question.detail.contains(qu)
         )
    ).order_by(‘creat_time‘)
    return render_template(‘index.html‘,questions = ques)
 <form action="{{ url_for(‘search‘) }}" method="get" style="float: right">
    <input name="q" type="text" class="form-control" style="width: 250px"  placeholder="请输入关键字" >
    <button type="submit" style="width: 80px">搜索</button>
     </form>

 

js搜索框实现自动搜索功能

  做项目的时候,老板让我自己封装一个搜索功能,就类似于百度这种  输入了字符之后,就可以自动搜索数据,而且还会出现一个下拉框供用户选择,我觉得我老板有问题,网上有这么多插件,不仅封装好了,性... 查看详情

使用ajax实现搜索功能

      最近要做一个搜索功能,网上搜了一圈,终于做出来了,这里分享我的方法,希望对大家有用,不足之处还请指教。   这里使用ajax提交数据,配合jquery将数据显示出来。   用jq的keyup触... 查看详情

搜索功能实现

一个easter过得够无聊的,就想能不能把搜索功能实现一下,可以理解某些数据量大的客户在使用这个系统的时候,没有搜索是多么的抓狂。可是实现搜索也不是那么简单,在tree里面一个个找过来,要能往前还要能往后找,想想... 查看详情

实现搜索功能

准备视图函数search()#搜索@app.route(‘/search/‘)defsearch():qu=request.args.get(‘q‘)#ques=Question.query.filter(Question.title.contains(qu))#单一条件查询ques=Question.query.filter(or_(Question.title.contains(qu),Que 查看详情

django实现搜索功能

实现功能:用户在搜索框输入关键词,过滤出带有关键词的文章。新闻模型如下:models.pyclassNotices(models.Model):Category_List=((‘新闻动态‘,‘新闻动态‘),(‘通知公告‘,‘通知公告‘),)NoticeID=models.AutoField(primary_key=True)NoticeTitle=model... 查看详情

Codeigniter:实现搜索功能

】Codeigniter:实现搜索功能【英文标题】:Codeigniter:implementingsearchfunctionality【发布时间】:2020-07-1811:02:23【问题描述】:错误:遇到PHP错误严重性:通知消息:未定义变量:记录文件名:views/Search_data.php行号:80回溯:文件:/hom... 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情

实现搜索功能

准备视图函数search()修改base.html中搜索输入框所在的<formaction="{{url_for(‘search‘)}}"method="get">  <inputname="q"type="text"placeholder="请输入关键字">完成视图函数search()获取搜索关键字q=request.args.get(‘q’)条件查询 查看详情