我一直在为我的大学活动开发一个基于烧瓶的应用程序。我使用了一个SQLite数据库以及Peewee和它的剧场扩展。有一个特定页面,我需要显示数据库表中的所有条目。
# The playhouse.flask_utils.FlaskDB object accepts database URL configuration.
DATABASE = 'sqliteext:///%s' % os.path.join(APP_DIR, 'blog.db')
DEBUG = False
# Create a Flask WSGI app and configure it using values from the module.
app = Flask(__name__)
app.config.from_object(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# FlaskDB is a wrapper for a peewee database that sets up pre/post-request
# hooks for managing database connections.
flask_db = FlaskDB(app)
# The `database` is the actual peewee database, as opposed to flask_db which is
# the wrapper.
database = flask_db.database
有一个Entry类,带有保存和查询功能
class Entry(flask_db.Model):
title = CharField()
slug = CharField(unique=True)
content = TextField()
tags = TextField()
published = BooleanField(index=True)
is_highlight = BooleanField(index=True)
category = TextField()
date = TextField()
time = TextField()
contact = TextField()
fee = TextField()
image = TextField()
timestamp = DateTimeField(default=datetime.datetime.now, index=True)
@property
def html_content(self):
"""
Generate HTML representation of the markdown-formatted blog entry,
and also convert any media URLs into rich media objects such as video
players or images.
"""
hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
extras = ExtraExtension()
markdown_content = markdown(self.content, extensions=[hilite, extras])
oembed_content = parse_html(
markdown_content,
oembed_providers,
urlize_all=True,
maxwidth=app.config['SITE_WIDTH'])
return Markup(oembed_content)
def save(self, *args, **kwargs):
# Generate a URL-friendly representation of the entry's title.
if not self.slug:
self.slug = re.sub('[^\w]+', '-', self.title.lower()).strip('-')
ret = super(Entry, self).save(*args, **kwargs)
# Store search content.
return ret
@classmethod
def public(cls):
return Entry.select().where(Entry.published == True)
呈现页面的功能是
@app.route('/events')
def events():
query = Entry.public()
return object_list(
'list.html',
query,
check_bounds=False)
使用sqlite3为ubuntu在命令行上运行时的查询返回所有26个条目,但是在应用程序中,它只返回其中的20个。我通过删除表中的一个条目来验证,并且它的位置是由之前不可见的行之一。我查看了peewee和sqlite的多个站点和文档,但还没有找到解决方案。我甚至尝试改变像Page Size这样的编译语句。我认为更改数据库的run-time limits可以帮助我,但我还没有找到改变或修改它的方法。无论如何要解决它。或者迁移到MariaDB会解决它。如果是这样的唯一解决方案。
答案 0 :(得分:0)
我只需在对象列表中使用'paginate_by = my-number'。