Pagination in Flask-SQLAlchemy
Вставка
- Опубліковано 25 лип 2024
- Using pagination in Flask-SQLAlchemy is important because often times you'll have large datasets in your database that you don't want to appear in your template all at once. By calling the paginate method on your SQLAlchemy model query, you'll be able to return only the results you want while still having access to the others by going to a different page. In this video, I show you exactly how to use pagination in Flask-SQLAlchemy, and by the end of it, you should know enough to use paginate the results in your apps.
Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted.com/coaching
Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql
Documentation Referenced in Video:
flask-sqlalchemy.pocoo.org/2.1...
flask-sqlalchemy.pocoo.org/2.1...
Flask Cheatsheet: prettyprinted.com/flaskcheats...
Twitter: / pretty_printed
Github: github.com/prettyprinted
Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql
Can't tell you how much you have helped me learn, every time I need to learn something within flask you have a video to get me going. You are the man my friend
Very good. Its help me so much. Congratulations from Brazil
Thank you. It's been very helpful.
You're welcome! Thanks for watching.
Excellent, thanks for the video!
You're welcome! Thanks for watching.
Great tutorials as always
Thanks, I appreciate it!
Muchas gracias por este tutorial. Me ha venido muy bien.
You're welcome! Thanks for watching.
The king of flask you are
Thanks! Interesting videos!
Thanks for watching!
thank uuuuuu so much it was so helpful
You're welcome! Thanks for watching.
thank you bro!
Saludos desde Chile , buenos vídeos
Gracias!
Appreciate you!
And I appreciate you for watching.
thanks a lot...
You're welcome! Thanks for watching.
thank you
great video !! , how about pagination with filter ?
Excellent Anthony- As always. Thank you!!! The link provided to access the source code reports an error 404: Page not found
This is a good example of offset based pagination. Is there any example for cursor based pagination? I am looking for a good example using flask sqlalchemy with timestamp been used in the cursor based .please help
hi thanks for great video. i'm wondering what is difference between your method of pagination and other method like so:
pagination = Pagination(page, PER_PAGE, count)
return render_template('some.html', pagination=pagination, users=users)
Also, how can I change font size of the user.iter_pages() links? Is it through some CSS style? There alternative method I mentioned has documentation on changing the font size and padding, etc through CSS. How can I do it for your method? Thanks
Hi, I really like your Flask Tutorials! Do you mind if I put your CheatSheet on one of my Github Projects? Of course I will link to your website and give the credit to you
Hey anthony, how can I achieve this... say I want to pass an index for eg: 0 it should return 0 to 5 records and if index is 1 it should return 6 to 10 record in json if possible......using flask sql alchemy.....thanks
Best video tutorial on flask pagination, but please make a video on flask infinite scrolling as it is hard to find on the internet.
That's a good idea. I'll add it to my list. Thanks for watching.
Hi I am not able to post through all form data from paginated pages. For example if I have loads of checkboxes on each row, I am not when I submit my form. I only get the data for the last page number when an items was selected. Is there a way around this.
hey Anthony,you explanation Power is Wonderfull..I am getting error in jinja syntax that 'list object is not iterable' for threads.iter_pages.How does I solve this ??
what if my 'thread' function got already some arguments ?
Wonderful video. I am facing an issue. I am able to pull the rows and navigate to rows. I need to receive additional comments for the row presented to the user and update back to the database. What is the best approach to handle this situation?
You can associate the additional comments with the ID of each row and then use that ID to query for the row again to update it.
How can i dynamically change the per_page value to show rows in a table like 5, 10, 20, etc. I managed to sort them but when navigation to next page it shows the rows as only 5 or the number i have previously set.
Hello,I'm having trouble trying to paginate a modal box using flask-sqlalchemy pagination method because when i change the page the modal box close automatically.Can you help me on how to maginate a modal box without it closing? i tried using Ajax but not worked.
That's too broad of a question to answer over UA-cam. If you have code, you can send it to anthony@prettyprinted.com so I can take a look.
Is there a version that can be used with pymongo db?
Look into Flask-MongoAlchemy.
Hi, can you please provide the method of search of filter by name or I'd
It would look something like this: .filter(db.or_(User.id == id, User.name == name)))
Any way to add a search box with this to search for a specific result?
That's a pretty broad question, but basically, yes you can add a search box.
Thanks for the quick reply!
Okay I'll be more specific, I've used the method in this video to paginate some campsites in a website i'm making. It would be a lot better if the user had the option to type in some characters to filter the results.
Would you recommend anything for this functionality?
Really helpful vid btw, you explain things very well. I've subbed to your channel.
Still a bit broad because it depends on exactly how you want it to work.
But I'll assume the search box is just a form. When the form gets submitted, you can add arguments to the URL query string that would get read by the route that queries the database.
oshna lekin zo'r chiiqbdi! ashnaqa davom etorin )) (Anjanlilar tushundi)
Nice video Anthony thanks you really explain this well but i want to ask you one question , i am adding full text search to my app using whooshalchemy and i want to paginate my results how can i do this, here is my code but i keep on getting and error.My search code code works well but i get and error only when i try to add pagination to the results
@app.route('/search_results//')
@app.route('/search_results/')
def search_results(query,page=1):
results = User.query.whoosh_search(query, or_=True).paginate(page=page, per_page=2,error_out=True)
return render_template('search_results.html',
results=results,
query=query
)#closing redirect
It's a bug in WhooshAlchemy. See here: github.com/gyllstromk/Flask-WhooshAlchemy/pull/14
Try using a fork of the extension: github.com/dhamaniasad/Flask-WhooshAlchemy
I have some problem. I want to paginate the data from my database but when i run application i get the message: "werkzeug.routing.BuildError: Could not build url for endpoint 'personal_page'. Did you forget to specify values ['page_num']?". I downloaded your application and it works properly, but mine doesn't... What i have do to here? My code below:
@app.route('/personal_page/', methods=['GET', 'POST'])
@login_required
def personal_page(page_num):
threads = Users.query.paginate(per_page=10, page=page_num, error_out=True)
return render_template('personal_page.htm', threads=threads,
title = 'Personal page',
name = current_user.username)
Sorry for bad English btw
When using url_for, are you including the page number? url_for('personal_page', page_num=the_page_num)
Pretty Printed Yes, I solved that already, but thanks for reply! You are awesome! :D
como resolviste?
all the time he says cheat sheet, I hear chi chi..... :)
this_tutorial_is_fake = True