Giter Site home page Giter Site logo

django-paginator's Introduction

django-paginator

A simple paginator tag and utils

Installation

  1. Add the paginator directory to your Python path.
  2. Add the 'paginator' directory in settings.INSTALLED_APPS.
  3. Add 'django.core.context_processors.request' in settings.TEMPLATE_CONTEXT_PROCESSORS

Usages

  1. In template example:

    {% load paginator_tag %}
    {% paginate object_list %}
    {% paginator_nav %}
    <ul>
    {% for obj in object_list %}
        <li>{{ obj }}</li>
    {% endfor %}
    </ul>
    {% paginator_nav %}
    
  2. In views

    views.py:

    from django.views.generic.simple import direct_to_template
    from paginator import paginate
    
    def example(request):
        object_list = [{'item': i} for i in xrange(1, 100)]
        paginator, object_list = paginate(object_list, request)
    
        return direct_to_template(request, 'example.html',
                {'object_list': object_list, 'paginator': paginator})
    

    example.html:

    {% load paginator_tag %}
    {% paginator_nav paginator %}
    <ul>
    {% for obj in object_list %}
        <li>{{ obj }}</li>
    {% endfor %}
    </ul>
    {% paginator_nav paginator%}
    

Template tags

  • paginate - for paginate objetct list:

    {% paginate object_list [per_page] [as paginator] %}
    
  • paginator_nav - build navigation page:

    {% paginator_nav [paginator] %}
    

template for paginator_nav in paginator/paginator_tag.html

Tests

Do run tests:

python2 manage.py test paginator

django-paginator's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.