0

In my flask application which I use flask-migrate and Alembic I got this URL" /user/1?sort=ascmonkey=< flask_sqlalchemy.Pagination+object+at+0x7f6a8077ea10 >",while this part is extra < flask_sqlalchemy.Pagination+object+at+0x7f6a8077ea10 > where is it come from and how can I get rid of that?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>
LiLi
  • 301
  • 2
  • 7
  • 21

1 Answers1

0

monkey is a paginated list of users, based on the query you've shown. The actual users are stored in monkey.items, a list. Based on what you've shown, you either want to iterate over those items to generate individual urls, or you meant for monkey to be one user rather than a paginated list. Right now you're doing something along the lines of url_for('user', monkey=monkey), so Flask is placing the string representation of the pagination object into the query params.

davidism
  • 121,510
  • 29
  • 395
  • 339