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.
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.
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.
The url
template tag works different in Django 1.4, see the release notes for more info.
{% 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
Bits and bites of the following projects were re-used to build django-compat.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4