在我使用flask-migrate和Alembic的烧瓶应用程序中,我得到了这个URL" /用户/ 1排序= ascmonkey = LT?; flask_sqlalchemy.Pagination + object + at + 0x7f6a8077ea10>&#34 ;,而这部分是额外的< flask_sqlalchemy.Pagination + object + at + 0x7f6a8077ea10>它来自哪里,如何摆脱它?Thanx
View.py:
@layout.route('/user/<int:page>', methods = ['GET', 'POST'])
def user(page=1, sort='normal'):
user = g.user
#condition to sort base on ascending
if request.args.get('sort') =='asc':
sortBy = 'asc'
monkey = Users.query.order_by(Users.name.asc()).paginate(page, MONKEYS_PAGE)
MONKEYS_PAGE)
return render_template('Users.html',
user = user,
title ='Home',
monkey = monkey,
sortBy = sortBy
)
User.html
<div class="text-right sortby">
<span>Sort by</span>
<a href="{{ url_for('layout.user', page = '1', sort = 'asc', monkey = monkey) }}" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-sort-by-alphabet"></span>
name
</a>
<a href="{{ url_for('layout.user', page = '1', sort = 'friendnum', monkey = monkey) }}" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-link"></span>
number of friends
</a>
<a href="{{ url_for('layout.user', page = '1', sort = 'bf', monkey = monkey) }}" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-link"></span>
name of best friends
</a>
</div>
答案 0 :(得分:0)
monkey
是一个分页的用户列表,基于您显示的查询。实际用户存储在monkey.items
列表中。根据您显示的内容,您要么迭代这些项目以生成单个网址,要么您希望monkey
成为一个用户而不是分页列表。现在你正在做url_for('user', monkey=monkey)
行,所以Flask将分页对象的字符串表示放入查询参数中。