def search(keyword):
Blog.update()
pt = request.args.get('page')
if pt is None:
page = 1
else:
page = int(pt)
try:
keywords = keyword.split()
from sqlalchemy import and_, or_
rules = and_(
*[or_(Post.title.ilike('%%%s%%' % k), Post.summary.ilike('%%%s%%' % k), Post.content.ilike('%%%s%%' % k))
for k in keywords])
pagination = Post.query.filter(rules).order_by(Post.date.desc()).paginate(
page=page, per_page=current_app.config['FMBLOG_PER_PAGE'])
except Exception:
return render_template('404.html', e='Error: Empty Keyword', site=current_app.config['FMBLOG_SITE'],
value={}), 404
return render_template('search.html', value={'keyword': keyword},
pagination=pagination, endpoint='main.search',
page_list=get_page_list(pagination, page),
tags=Tag.query.order_by(Tag.count.desc()).all(),
cats=Category.query.order_by(Category.count.desc()).all(),
site=current_app.config['FMBLOG_SITE'])
评论列表
文章目录