python - 使用 flask_paginate (pymongo) 实现分页
问题描述
我想使用 flask_paginate 实现烧瓶分页。我正在使用 MongoDB
我已经制定了这条“家”路线来实现这一点。但它不起作用。
这是我的家乡路线代码
@app.route("/")
@app.route("/home")
def home():
if current_user.is_authenticated:
search = False
q = request.args.get('q')
if q:
search = True
page = request.args.get(get_page_parameter(), type=int, default=1)
posts=mongo.db.articles
#allpost=posts.find().limit(5)
it=current_user.user_json['interest']
allpost=posts.find( {'NewsType': it } )
pagination = Pagination(page=page,per_page=5 ,total=allpost.count(), search=search, record_name='allpost')
#flash(session['email'])
return render_template('index.html', posts=allpost,pagination=pagination)
else:
return redirect(url_for('login'))
#return render_template('login.html', title='Login',form=LoginForm())
{% extends "layout.html" %}
{% block content %}
{% for post in posts %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.email }}</a>
<small class="text-muted">{{ post.Date }}</small>
</div>
<h2><a class="article-title" href="{{url_for('post',post_id=post._id)}}">{{ post.Heading }}</a></h2>
<p class="article-content">{{ post.NewsType }}</p>
</div>
</article>
{% endfor %}
{% endblock content %}
{{ pagination.links }}
这是我正在使用的 index.html 文件
我想要每页 5 篇文章。有人可以告诉我为什么这段代码不起作用,因为我可以转到下一页,但它显示所有文章而不是 5
解决方案
推荐阅读
- flutter - 如何在 GetxController 中将 Get.arguments 处理为 null
- java - 使用扫描仪时如何解决此错误
- android - 搜索 Dronekit-Android 文档
- ios - 如何在 UINavigationBarAppearance 中设置阴影半径?
- php - 为什么我的 PHP 代码不起作用,HTML 网站?
- php - PHP脚本允许用户从远程FTP服务器下载文件
- android - Flutter android方向卡在横向模式下
- python - 内存使用matplotlib - 如何清理内存?
- android - 导航组件隐式深层链接以空的 backstack 打开屏幕
- python - 如何使一个对象一个接一个地移动?