Python Forum
[Flask] How to paginate a list of posts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Flask] How to paginate a list of posts
#1
I created a list of the posts I want to display. How would I go about paginating a list of posts? If you need code I can give it, but I just need an example of taking a list of posts, messages, etc. and paginating them. Thanks in advance!
Reply
#2
On the server have a list,send list to html template.
In html template loop over list with jinja.
server:
from flask import Flask, render_template, jsonify

app = Flask(__name__)
@app.route('/')
def bar():
    lst = ["Python", 'HTML', 'JavaScript'] 
    return render_template("index_page.html", lst=lst)

if __name__ == '__main__':
    app.run(debug=True)
index_page.html:
<!doctype html>
<html>
<head>
  <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style.css') }}" />
</head>
<body>
  <p>Navigation pagination:</p>
  <div class="pagination">
    <ul>
      <a href="#" class="active">Home</a>
      {% for page in lst %}
      <a href="#">{{ page }}</a>
      {% endfor %}
    </ul>
  </div>
</body>
</html>
Reply
#3
Not what I was looking for but totally my fault for the lack of communication.
posts = []
for following in current_user.followingList:
    post = Post.query.filter_by(username=following).first()
    if post:
        posts.append(post)
posts = Post.query.order_by(order).paginate(parameters) #This will give me all the posts but I only want to use the posts from the list
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 3,502 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  [Flask]filter posts from list SheeppOSU 0 2,260 May-30-2019, 03:48 PM
Last Post: SheeppOSU
  Paginate json data in flask or jinja2 soli1994 1 8,298 Jun-28-2018, 06:00 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020