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) )) return render_template(‘switch.html‘,wenda = ques)
<form action="{{ url_for(‘search‘) }}"method="get"> <input name="q" type="text" placeholder="请输入关键字"> <button type="submit">搜索</button> </form>