用Sqlalchemy和JInja进行烧瓶分页。错误:werkzeug.routing.BuildError werkzeug.routing.BuildError :(“用户”,{“页面”:2},无)

时间:2018-07-08 18:47:22

标签: flask pagination sqlalchemy jinja2

嗨,我想与jinja2建立分页-

请帮助我

@app.route('/users')
def all_users():
   users_list = User.query.paginate(1, per_page=2,error_out=False)
   if users_list.has_next:
       next_url = url_for('users', page=users_list.next_num)
   if users_list.has_prev :
       prev_url = url_for('users', page=users_list.prev_num)
   return render_template("users.html",  users=users_list.items,
                          next_url=next_url, prev_url=prev_url)

<------ users.html ----->

{% for user in users %}
        <table>
        <tr valign="top">
            <td>{{ user.id }}</td>

            <td>{{ user.user_fname }}</td>

        </tr>
    </table>
{% endfor %}

    {% if prev_url %}
    <a href="{{ prev_url }}">Newer posts</a>
    {% endif %}

    {% if next_url %}
    <a href="{{ next_url }}">Older posts</a>
    {% endif %}

每次我收到这样的错误-

werkzeug.routing.BuildError werkzeug.routing.BuildError:('users',{'page':2},None)

我该如何解决?

1 个答案:

答案 0 :(得分:0)

也许您应该像这样url_for(".users", page=users_list.next_num)进行修复, 确保定义函数def users(page)