<form action="{{url_for('search')}}" method="get" class="navbar-form navbar-left">
<div class="form-group"><input type="text" class="form-control" name="q" placeholder="输入您感兴趣的"></div>
<button type="submit" class="btn btn-default" style=" 70px">查询</button>
</form>
@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('-creatTime')
return render_template('shouye.html',questions=ques)
@app.route('/')
def shouye():
context={
'questions': Question.query.order_by('-creatTime').all()
}
return render_template('shouye.html', **context)