Reputation: 30101
To use flickr as an example, a request URL looks something like this:
'http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=' + settings.FLICKR_API_KEY + '&user_id=' + userid + '&format=json&per_page' + per_page + '&page=' + page + '&nojsoncallback=1'
where page
controls which page to display and per_page
controls the number of photos to return
To simplify matters, let's make per_page
fixed. So my question is, how can I implement a paging system that allows a user to go one page forwards or back at anytime on the webpage?
I imagine I would need to pass the page number to iterate through the request URL such that the right data is displayed. SO I guess I'm not sure how to tie the template to the views.py. Essentially, I'm looking for the Django version of this Rails question.
The examples and plugins I have come across so far (e.g. django-pagination) mainly deal with pagination resulting from a database query.
Upvotes: 2
Views: 1658
Reputation: 2426
With your description, I would say start with page = 1. If page = 1, have one link in your page to go forward, that will load page = 2. If you're in any other page other than one generate two links, one for the previous and other for the next page, relative to the current one.
If you want better help you really have to show us some code.
Upvotes: 0
Reputation: 15936
Django-pagination will work with any list of objects -- not just calls from the database. The example here actually starts off with an example that has nothing to do with local models or databases.
For an API-type call, you'd just need to read your objects into a list, and then create a new Paginator objects based off of that list. All you have to do is give it the number of objects you want per page. It's really very simple.
Upvotes: 3