当前位置:  开发笔记 > 编程语言 > 正文

与烧瓶和Peewee的分页

如何解决《与烧瓶和Peewee的分页》经验,为你挑选了1个好方法。

我正在尝试使用paginate查询的结果.我想使用的功能object_list中的.FlaskPeeweeplayhouse.flask_utils

您可以看到object_list似乎非常简单的示例,以下代码是我正在努力工作的代码:

from flask import Flask
from playhouse.flask_utils import object_list
from peewee import *
from database import *

@app.route("/items/")                                                         
def items():                                                                  
    all_items = Quote.select()                                                     
    return object_list("items.html", all_items) 

该模板items.html包含以下内容:

Hello world

{% for item in all_items %}

{{ item.text }}

{% endfor %} {% if page > 1 %} {% endif %} {% if pagination.get_pages() > page %} {% endif %}

当然,我运行python app.py但收到500内部服务器错误.我有兴趣对我的查询结果进行分页,任何想法我怎么能实现这一点?或者你能发现我在这里做错了吗?先感谢您.

编辑#1,终端中出现以下错误:

127.0.0.1 - - [09/Jan/2016 20:47:17] "GET /items/ HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/web/index.py", line 19, in items
    return object_list("items.html", all_items)
  File "/usr/lib/python2.7/site-packages/playhouse/flask_utils.py", line 64, in object_list
    **kwargs)
  File "/usr/lib/python2.7/site-packages/flask/templating.py", line 128, in render_template
    context, ctx.app)
  File "/usr/lib/python2.7/site-packages/flask/templating.py", line 110, in _render
    rv = template.render(context)
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/web/templates/items.html", line 9, in top-level template code
    {% if pagination.get_pages() > page %}
UndefinedError: 'playhouse.flask_utils.PaginatedQuery object' has no attribute 'get_pages'

coleifer.. 7

没有get_pages()方法.使用:get_page(x)获取一页结果.使用get_page_count()获得的总页数.

这些都记录在这里:http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PaginatedQuery



1> coleifer..:

没有get_pages()方法.使用:get_page(x)获取一页结果.使用get_page_count()获得的总页数.

这些都记录在这里:http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PaginatedQuery


我以为我在其他地方看到过`coleifer`,然后我记得github上`peewee`的网址:https://github.com/coleifer/peewee :)
推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有