Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A helper app for sorting objects in Django templates.

Project Description

django-sorter helps with sorting objects in Django templates without modifying your views, can be used multiple times on the same page or template, provides helpers to easily generate links and forms to switch the sorting criteria (including the sort order) and has ~100% test coverage.


  1. Get the app with your favorte Python packaging tool, e.g.:

    pip install django-sorter
  2. List this application in the INSTALLED_APPS setting. Your settings file might look something like:

        # ...
  3. If it’s not already added in your setup, add the request template context processor to the TEMPLATE_CONTEXT_PROCESSORS setting (you might need to add it):

        # ...
  4. Specify the allowed sorting criteria, for at least the default 'sort' sorting querystring parameter:

        'sort': ['first_name', 'creation_date', 'title'],
  5. Add this line at the top of your template to load the sorting tags:

    {% load sorter_tags %}
  6. Decide on a variable that you would like to sort, and use the sort tag on that variable before iterating over it.

    {% sort objects as sorted_objects %}
  7. Optionally, you can display different sort links or forms:

       <th>{% sortlink by "first_name" %}By first name{% endsortlink %}</th>
       <th>{% sortlink by "creation_date,-title" %}By creation date and title{% endsortlink %}</th>

    The template tag takes a comma separated list of sorting statements. It also is a block tag and allows you to set the label of the generated link. The previous snippet will be rendered like this:

        <th><a href="/?sort=first_name" title="Sort by 'first_name' (asc)">By name</a></th>
        <th><a href="/?sort=creation_date,-title" title="Sort by 'creation_date' (asc) and 'title' (desc)">By creation and title</a></th>

    Similarly the {% sortform %} template tag renders a form instead of a simple link.

Release History

Release History

This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-sorter-0.2.tar.gz (9.3 kB) Copy SHA256 Checksum SHA256 Source May 27, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting