Skip to content

Commit

Permalink
added first attempt of pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKayAce committed Jul 16, 2019
1 parent cb68d6f commit 082e1da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Binary file modified app.db
Binary file not shown.
12 changes: 8 additions & 4 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def index():
db.session.commit()
flash("your post is now live")
return redirect(url_for("index"))
posts = current_user.followed_posts().all()
return render_template('index.html', title = "Home Page", form = form, posts=posts)
page = request.args.get("page", 1, type=int)
posts = current_user.followed_posts().paginate(
page, app.config["POSTS_PER_PAGE"], False)
return render_template('index.html', title = "Home Page", form = form, posts=posts.items)

@app.route("/login", methods=["GET","POST"])
def login():
Expand Down Expand Up @@ -137,5 +139,7 @@ def unfollow(username):
@app.route("/explore")
@login_required
def explore():
posts = Post.query.order_by(Post.timestamp.desc()).all()
return render_template("index.html",title="Explore", posts=posts)
page = request.args.get("page", 1, type=int)
posts = Post.query.order_by(Post.timestamp.desc()).paginate(
page, app.config["POSTS_PER_PAGE"], False)
return render_template("index.html",title="Explore", posts=posts.items)
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class Config:
MAIL_USE_TLS = os.environ.get("MAIL_USE_TLS") is not None
MAIL_USERNAME = os.environ.get("MAIL_USERNAME")
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD")
ADMINS = ["[email protected]"]
ADMINS = ["[email protected]"]
POSTS_PER_PAGE = 3

0 comments on commit 082e1da

Please sign in to comment.