Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-compat

For- and backwards compatibility layer for Django 1.4.x to 1.8-alpha

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

Compatible objects

  • BytesIO
  • clean_manytomany_helptext
  • EmailValidator
  • force_text
  • get_indent
  • get_model_name
  • get_user_model
  • get_username_field
  • handler404
  • handler500
  • HttpResponseBase
  • import_string
  • include
  • JsonResponse
  • parse_qs
  • patterns
  • python_2_unicode_compatible
  • simplejson
  • smart_text
  • StringIO
  • unquote_plus
  • url
  • urlencode
  • urlparse
  • urlunparse
  • URLValidator
  • user_model_label
  • View

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

compat.py

Bits and bites of the following projects were re-used to build django-compat.

About

For- and backwards compatibility layer for Django 1.4.x to 1.8-alpha

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages