实现搜索功能
- 准备视图函数search()
- 修改base.html 中搜索输入框所在的
<form action="{{ url_for('search') }}"method="get"> <li><input type="text" name="search" class="form-control" style="width: 200px"></li> <button type="submit" class="btn btn-default">搜索</button> </form>
3.完成视图函数search()
@app.route('/search/',methods=['GET','POST']) def search(): search = request.args.get('search') question = Ques.query.filter( or_( Ques.title.contains(search), Ques.detail.contains(search) ) ).order_by('-creat_time') return render_template('lx3.html',question=question)