【发布时间】:2013-03-27 05:06:20
【问题描述】:
我有一个小的 Flask 应用程序,它可以呈现博客文章:
views.py:
class ListView(MethodView):
def get(self, page=1):
posts = Post.objects.all()
return render_template('posts/list.html', posts=posts)
这一切都很好,但我想为posts 对象添加分页。查看project docs,我看到有一个分页类。
所以我尝试了这个:
class ListView(MethodView):
def get(self, page=1):
posts = Post.objects.paginate(page=page, per_page=10)
return render_template('posts/list.html', posts=posts)
但现在我得到一个错误:
TypeError: 'Pagination' object is not iterable
那么如何在模板中遍历我的posts?
【问题讨论】:
-
你的模板代码是什么?可以分享一下吗?
标签: python mongodb flask mongoengine