0

我一直在为我的大学活动开发一个基于烧瓶的应用程序。我使用了一个 SQLite 数据库和 Peewee 以及它的 playhouse 扩展。有一个特定页面,我需要在其中显示数据库表中的所有条目。

# 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)

使用 ubuntu 的 sqlite3 在命令行上运行的查询返回所有 26 个条目,但是在应用程序中,它只返回其中的 20 个。我通过从表中删除其中一个条目来验证,它的位置被之前不可见的行之一占据。我查看了 peewee 和 sqlite 的多个站点和文档,但还没有找到解决方案。我什至尝试更改诸如Page Size之类的编译指示语句。我认为更改数据库的运行时限制可以帮助我,但我还没有找到改变或修改它的方法。有没有办法修复它。或者迁移到 MariaDB 会解决它。如果是这样,那是唯一的解决方案。

4

1 回答 1

0

我只需要在对象列表中使用'paginate_by = my-number'。

于 2018-01-20T15:22:18.530 回答