@
honmaple 嗯,是用 wtforms 的。现在遇到的问题是:在第一页通过 form 取到 keyword 之后,传给模板,分页的下一页是通过 SALAlchemy 的 paginate()方法,我在那里添加 url_for 参数,返回值是空的。搞得下一页,就成了空白。。。
#
form.pyclass SearchForm(Form):
search_keyword = StringField('', validators = [DataRequired()])
submit = SubmitField('Start Search')
#
view.py@
app.route('/search', methods=['POST', 'GET'])
def search():
form = SearchForm():
keyword = form.search_keyword.data
page = request.args.get('page', 1, type=int)
value = request.args.get('keyword')
if form.validate_on_submit():
pagination = Post.query.filter(Post.content.like(keyword))paginate(
page, per_page=current_app.config['default'], error_out=False)
posts = pagination.items
return render_template('search.html', posts=posts, pagination=pagination, form=form, value=value)
#search.html
<div class="list">
{% include 'list.html' %}
</div>
{% if pagination %}
<div class="pagination">
{{ macros.pagination_widget(pagination, '.search', value=value)}}
</div>
{% endif %}