Skip to main content

Adds infinite scroll to any page

Project description

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:

    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.

    pip install django-infinite-scroll

Add to settings.py

    INSTALLED_APPS = [
        # ...
        'infscroll',
    ]

First, let's make a view that will load the dynamic content:

    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

    path('more/', myapp.views.more, name='more'),

Finally, Add to the view you want to show the infinite scroll:

    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:

    {% load infinite_scroll %}
    <html>
        <body>
            <p>Hello</p>
            <!-- The dynamically loaded items will show here -->
            {% infinite_scroll_box %}
            <!-- This can go in the end of the template. Will load css and js -->
            {% set_infinite_scroll %}
        </body>
    </html>

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:

    {% 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-infinite-scroll-0.1.7.tar.gz (28.0 kB view details)

Uploaded Source

File details

Details for the file django-infinite-scroll-0.1.7.tar.gz.

File metadata

  • Download URL: django-infinite-scroll-0.1.7.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for django-infinite-scroll-0.1.7.tar.gz
Algorithm Hash digest
SHA256 a0e5883ab061fbbb7a309c37d2103acb3a5435b302d1eb6758bb35c91c252606
MD5 864a4662353582f4cbe0f84bb52fc069
BLAKE2b-256 f0dec244c6dddd76dd5edfba9ab66bc40b160221857da315c50e12c3495b8da1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page