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


Messages In This Thread
RE: [Flask] How to paginate a list of posts - by snippsat - Jun-22-2019, 12:30 PM

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,623 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  [Flask]filter posts from list SheeppOSU 0 2,313 May-30-2019, 03:48 PM
Last Post: SheeppOSU
  Paginate json data in flask or jinja2 soli1994 1 8,369 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