Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gsteixeira/django-infinite-scroll
Add infinite scroll to any django app.
https://github.com/gsteixeira/django-infinite-scroll
Last synced: about 5 hours ago
JSON representation
Add infinite scroll to any django app.
- Host: GitHub
- URL: https://github.com/gsteixeira/django-infinite-scroll
- Owner: gsteixeira
- License: gpl-3.0
- Created: 2021-12-23T17:14:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-26T13:38:39.000Z (almost 3 years ago)
- Last Synced: 2024-10-08T15:38:24.835Z (29 days ago)
- Language: Python
- Size: 74.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-infinite-scroll
Add infinite scroll to any django app.## Features
- Allows to add infinite scroll to any page.
- Easy pagination.
- Works with Django's Queryset or any kind of lists.
- Requires no aditional javascript framework.
- Easy to install and set up.## Quicksetup
With docker compose:
``` bash
git clone https://github.com/gsteixeira/django-infinite-scroll.git
cd django-infinite-scroll/example/
docker-compose up
```Go to http://localhost:8000 and try it out. 8)
## installation
Install module.
```bash
pip install django-infinite-scroll
```Add to settings.py
```python
INSTALLED_APPS = [
# ...
'infscroll',
]
```First, let's make a view that will load the dynamic content:
```python
from infscroll.views import more_items
def more(request):
# This is the list that will be paginated.
list_items = MyModel.objects.all()
return more_items(request, list_items,
# (optional) your custom template
template='more.html')
```Add it to urls.py
```python
path('more/', myapp.views.more, name='more'),
```Finally, Add to the view you want to show the infinite scroll:
```python
from infscroll.utils import get_pagination
def my_view(request):
# The list of items to be paginated. It can be any list of queryset.
list_items = MyModel.objects.all()
paginated = get_pagination(request, list_items)
# we must declare the url where it will load more stuff
data = {
'more_posts_url': reverse('more'),
}
# update with paginated info
data.update(paginated)
return render(request, 'my_view.html', data)
```Now add to your template:
```html
{% load infinite_scroll %}
Hello
{% infinite_scroll_box %}
{% set_infinite_scroll %}
```Now go to the page of "my_view", and you should have infinite scroll!
### (optional) If you want to use a custom "load_more" template
Here is an example:
```html
{% load infinite_scroll %}
{% for item in feed %}
{{ item }}
{% endfor %}
{% infinite_scroll_tags %}
```
Just add this *for loop* to iterate the list and include the scroll tags## Settings
PAGINATION_STEPS - the amount of items each step will load. Default to 10.
## Requirements
- python3
- django