Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

igsm '
igsm '
10,440 Points

How to create Infinite scrolling in Flask app?

Hi! I want my webpage to load more data on scroll. The application is built in Flask. I am a bit lost; how to implement that and from where to start? Can anyone help please by recommending something or sharing a good source of explanation? I was unable to find something meaningful for Flask app so far. Cheers.

Kenneth Love ?

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You'd need a view that takes a starting place for fetching records. Let's say you do 10 records at a time. When you hit that view, and you say "start=10", that view gives you items 10-20 back as JSON or whatever you need. Then, when they scroll far enough, you ask for "start=20" and get back the next set of items.

As for the requesting and fetching, that would be done though JavaScript.

igsm '
igsm '
10,440 Points

Thank you. Is AJAX anyhow required in your method or will it simply work if a JS function request for the view function every time a user hits the end?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

It will involve AJAX, yes, because you'll be receiving a new partial bit of data from the server asynchronously. It doesn't have to be XML, of course.