I want to implement flask pagination using flask_paginate. I am using MongoDB
I have made this "home" route to implement this. But it's not working.
This is my home route code
@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 }}
And this is the index.html file i am using
I want 5 articles per page. Can somebody please tell me why this code not working because I can go next page but it shows all articles instead of 5