Skip to main content

For- and backwards compatibility layer for Django 1.4, 1.7 and 1.8

Project description

[![Build Status](](
[![Stories in Ready](](

For- and backwards compatibility layer for Django 1.4, 1.7 and 1.8

~~Consider [django-compat]( as an experiment based on the discussion [on reddit]( Let's see where it goes.~~

What startet as an experiment based on [this discussion on reddit]( has proven to be true in real life. django-compat is [currently being discussed]( on the django-developer mailing list.

django-compat is under active development. To learn about other features, bug fixes, and changes, please refer to the [changelog](

# Who uses django-compat

Two popular examples of open source reusable app that uses django-compat are [django-hijack]( and [django-background-tasks](
Want to have yours listed here? Send us a PR.

# Why use django-compat

* Be able to use the LTS versions of Django and support newer versions in your app
* Use features from newer Django versions in an old one
* Manage and master the gap between different framework versions

# How to use django-compat

Install compat from the [PyPI]( or download and install manually. All relevant releases are listed [here under releases](

Using one of the compatible objects is easy. For example

from compat import patterns, url

urlpatterns = patterns('ABC.views',
url(r'^abc/$', 'abc', name='abc-link'),

See a full example [here](

# Compatible objects

* add_to_builtins
* atomic or commit_on_success (commit_on_success replaced by atomic in Django >=1.8)
* BytesIO
* clean_manytomany_helptext
* conditional_escape
* EmailValidator
* force_text
* format_html
* GenericForeignKey
* get_ident
* get_model_name
* get_user_model
* get_username_field
* handler404
* handler500
* HttpResponseBase
* import_module
* import_string
* include
* JsonResponse
* parse_qs
* patterns
* python_2_unicode_compatible
* simplejson
* slugify
* smart_text
* SortedDict
* StringIO
* unquote_plus
* url
* urlencode
* urlparse
* urlunparse
* URLValidator
* user_model_label
* VariableNode
* View
* resolve_url

# Manual adjustments

## ``url`` template tag

The ``url`` template tag works different in Django 1.4, see the [release notes]( for more info.

### Old, Django 1.4

{% url url_name %}
{% url url_name argument1 argument2 %}

### New, Django 1.4 + using forwards compatibility.

{% load url from future %}
{% url 'url_name' %}
{% url 'url_name' argument1 argument2 %}

The following ``sed`` command can be used to update your templates. Note that the ``{% load url from future %}`` is missing and must be added manually.

sed -i -r "s#\{% url ([a-zA-Z0-9_.:-]+)#\{% url '\1'#g" template.html

The inplace editing works great on Linux. If your are working on a Mac and you get the following error

"\1 not defined in the RE"

try the following command:

TMP_FILE=`mktemp /tmp/sed.XXXXXXXXXX`
sed -E "s#\{% url ([a-zA-Z0-9_.:-]+)#\{% url '\1'#g" template.html > $TMP_FILE
mv $TMP_FILE template.html

Source: [stackoverflow, Migrate url tags to Django 1.5](

# Resources and references

## Resources


Bits and bites of the following projects were re-used to build [django-compat](

- [x]
- [X]
- [X]
- [X]
- [ ] TODO: MinValueValidator, MaxValueValidator et al. (other relevant bits are included) Django 1.8
- [X]
- [ ]
- [ ]
- [ ]
- [ ]

# Changelog

### 2015/07/15

* ``add_to_builtins`` was added

### 2015/07/08
* ``get_query_set``/``get_queryset`` support was dropped again (see [#29](

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django-compat-1.0.7.tar.gz (12.4 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page