Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10, and 1.11

Related tags

Django django-compat
Overview

django-compat

Build Status Stories in Ready Coverage Status PyPI

Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10 and 1.11

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

What started as an experiment based on this discussion on reddit has proven to be true in real life.

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.

django-compat is free software. If you find it useful and would like to give back, please consider to make a donation using Bitcoin or PayPal. Thank you!

Compatible objects

Compatible object Specifically tested 1.8 1.9 1.10 1.11 Notes
BytesIO ✖️ ✔️ ✔️ ✔️ ✔️
DjangoJSONEncoder ✔️ ✔️ ✔️ ✔️ ✔️
EmailValidator ✖️ ✔️ ✔️ ✔️ ✔️
GenericForeignKey ✖️ ✔️
models.GenericForeignKey ✖️ ✔️ ✔️ ✔️ ✔️
HttpResponseBase ✖️ ✔️ ✔️ ✔️ ✔️
JsonResponse ✔️ ✔️ ✔️ ✔️ ✔️
LocaleRegexProvider ✖️ ✔️ ✔️ ✔️ ✔️
LocaleRegexURLResolver ✖️ ✔️ ✔️ ✔️ ✔️
NoReverseMatch ✖️ ✔️ ✔️ ✔️ ✔️
RegexURLPattern ✖️ ✔️ ✔️ ✔️ ✔️
RegexURLResolver ✖️ ✔️ ✔️ ✔️ ✔️
Resolver404 ✖️ ✔️ ✔️ ✔️ ✔️
ResolverMatch ✖️ ✔️ ✔️ ✔️ ✔️
SortedDict ✖️ ✔️ ✔️ ✔️ ✔️
StringIO ✖️ ✔️ ✔️ ✔️ ✔️
URLValidator ✖️ ✔️ ✔️ ✔️ ✔️
VariableNode ✖️ ✔️ ✔️ ✔️ ✔️
View ✖️ ✔️ ✔️ ✔️ ✔️
add_to_builtins ✖️ ✔️
admin_utils ✖️ ✔️ ✔️ ✔️ ✔️
atomic ✖️ ✔️ ✔️ ✔️ ✔️
clean_manytomany_helptext ✖️ ✔️ ✔️ ✔️ ✔️
clear_url_caches ✖️ ✔️ ✔️ ✔️ ✔️
close_connection ✖️ ✔️ ✔️ ✔️ ✔️
commit ✔️ ✔️ ✔️ ✔️ ✔️
commit_on_success ✔️ ✔️ ✔️ ✔️ ` ✔️ commit_on_success replaced by atomic in Django >= 1.8
force_text ✖️ ✔️ ✔️ ✔️ ✔️
format_html ✔️ ✔️ ✔️ ✔️ ✔️
get_callable ✖️ ✔️ ✔️ ✔️ ✔️
get_current_site ✖️ ✔️ ✔️ ✔️ ✔️
get_ident ✖️ ✔️ ✔️ ✔️ ✔️
get_mod_func ✖️ ✔️ ✔️ ✔️ ✔️
get_model ✖️ ✔️ ✔️ ✔️ ✔️
get_model_name ✖️ ✔️ ✔️ ✔️ ✔️
get_ns_resolver ✖️ ✔️ ✔️ ✔️ ✔️
get_resolver ✖️ ✔️ ✔️ ✔️ ✔️
get_script_prefix ✖️ ✔️ ✔️ ✔️ ✔️
get_template_loaders ✔️ ✔️ ✔️ ✔️ ✔️
get_urlconf ✖️ ✔️ ✔️ ✔️ ✔️
get_user_model ✖️ ✔️ ✔️ ✔️ ✔️
get_username_field ✖️ ✔️ ✔️ ✔️ ✔️
handler404 ✖️ ✔️ ✔️ ✔️ ✔️
handler500 ✖️ ✔️ ✔️ ✔️ ✔️
import_module ✔️ ✔️ ✔️ ✔️ ✔️
import_string ✖️ ✔️ ✔️ ✔️ ✔️
include ✖️ ✔️ ✔️ ✔️ ✔️
is_valid_path ✖️ ✔️ ✔️ ✔️ ✔️
parse_qs ✖️ ✔️ ✔️ ✔️ ✔️
patterns ✖️ ✔️ ✔️
python_2_unicode_compatible ✖️ ✔️ ✔️ ✔️ ✔️
render_to_string ✔️ ✔️ ✔️ ✔️ ✔️ The new function signature (https://docs.djangoproject.com/en/1.9/releases/1.8/#dictionary-and-context-instance-arguments-of-rendering-functions) is backported to pre-1.8.
resolve ✖️ ✔️ ✔️ ✔️ ✔️
resolve_url ✔️ ✔️ ✔️ ⚠️ ⚠️ 1.10: Reversing by dotted path has been removed
reverse ✖️ ✔️ ✔️ ✔️ ✔️
reverse_lazy ✖️ ✔️ ✔️ ✔️ ✔️
rollback ✔️ ✔️ ✔️ ✔️ ✔️ Transaction savepoint (sid) is required for Django < 1.8
set_script_prefix ✖️ ✔️ ✔️ ✔️ ✔️
set_urlconf ✖️ ✔️ ✔️ ✔️ ✔️
simplejson ✖️ ✔️ ✔️ ✔️ ✔️
slugify ✖️ ✔️ ✔️ ✔️ ✔️
smart_text ✖️ ✔️ ✔️ ✔️ ✔️
unquote_plus ✖️ ✔️ ✔️ ✔️ ✔️
url ✖️ ✔️ ✔️ ✖️ ✖️ Function used in urlpatterns
tempat.url ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
`uravy_multiplication_x: ✔️ ✔️ ✔️ ✔️ ✔️
urlparse ✖️ ✔️ ✔️ ✔️ ✔️
urlresolvers ✖️ ✔️ ✔️ ✔️ ✔️
urlunparse ✖️ ✔️ ✔️ ✔️ ✔️
user_model_label ✖️ ✔️ ✔️ ✔️ ✔️
templatetags.compat.verbatim ✔️ ✔️ ✔️ ✔️ ✔️ Templatetag; import with {% load verbatim from compat %}. 1.4: Does not allow specific closing tags, e.g. {% endverbatim myblock %}, and does not preserve whitespace inside tags.

Resources and references

Resources

compat.py

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

Changelog

2017/04/07

  • Update existing patches for Django 1.10

2016/08/02

  • Update existing patches for Django 1.10

2016/06/01

  • Add get_current_site and admin_utils

2016/05/11

  • Fix error when installing package under python 3.4

### 2015/11/12

  • Backport new render_to_string function signature to Django < 1.8
  • Backport verbatim tag to Django 1.4
  • Add get_template_loaders
  • Add close_connection
  • Improve JsonResponse backport to Django 1.4
  • Add tests for import_module, get_model and add_to_builtins
  • Anticipate renaming of django.core.urlresolvers to django.urls in 1.10
  • Avoid warnings in setup.py

2015/11/11

  • 1.9 compatibility for existing objects with the following changes:
    • add_to_builtins was removed for Django >= 1.9
    • GenericForeignKey` was moved to compat.models`` for Django >= 1.9

2015/07/15

  • add_to_builtins was added

2015/07/08

  • get_query_set/get_queryset support was dropped again (see #29)
Comments
  • get_query_set patching is very broken

    get_query_set patching is very broken

    The method included to patch get_query_set is very broken, and leads to some very bug code in circumstances where managers get subclassed - the behaviour of the subclass can be skipped. This is a very serious error for the case of Related managers, because it means that the limiting of the queryset that is added by the subclass get_query_set method gets skipped, so the related manager queries apply to all objects.

    I've created a branch that demonstrates the problem, adding 4 tests, 2 of which fails with Django 1.8, one fails with Django 1.5:

    https://github.com/spookylukey/django-compat/tree/get_query_set_patch_bug

    I've created a PR so that you can see the tests failing.

    The full details are explained in this blog post:

    http://lukeplant.me.uk/blog/posts/handling-django's-get_query_set-rename-is-hard/

    opened by spookylukey 5
  • Stop use django-nose as it doesn't support Django<1.8

    Stop use django-nose as it doesn't support Django<1.8

    I think use django-nose is a bad idea because it doesn't support Django<1.8. So we cannot test this version with the ./runtests.py.

    We should use Django test runner like made here: https://github.com/django-dbbackup/django-dbbackup/blob/master/runtests.py It also allow to launch any commands like manage.py.

    opened by ZuluPro 3
  • WIP django monkey-patcher

    WIP django monkey-patcher

    Hello,

    i'm planning a sprint at pyconfr to build a django compatibility module, which wouldn't behave like an intermediate module (like six for py3k, or like django-compat for django), but directly monkey-patch django with log-lifespan shims.

    Thus, django webmaster who want to upgrade wouldn't have to fork/monkeypatch all their broken dependencies, and minor django upgrades would REALLY be minor (i.e would NOT rename/remove methods and attributes used by tons of unmaintained libs).

    Would you be OK with integrating this monkey-patching utility to django-compat, to have an all-in-one solution, for BOTH library maintainers and library users ?

    opened by pakal 2
  • render_to_string - Django 1.8 changed how templates operate

    render_to_string - Django 1.8 changed how templates operate

    • http://django.readthedocs.org/en/latest/topics/templates.html#django.template.loader.render_to_string

    • based on https://github.com/mysociety/mapit/blob/master/mapit/djangopatch.py#L4-L12

      """ Django 1.8 changed how templates operate. """
      import django
      if django.get_version() >= '1.8':
          from django.template.loader import render_to_string
      else:
          from django.template import loader, RequestContext
      
          def render_to_string(template_name, context=None, request=None):
              context_instance = RequestContext(request) if request else None
              return loader.render_to_string(template_name, context, context_instance
      
    enhancement 
    opened by philippeowagner 2
  • New version brokes with Django==1.5.10 and six==1.3.0

    New version brokes with Django==1.5.10 and six==1.3.0

       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
         self.load_app(app_name, True)
       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/django/db/models/loading.py", line 94, in load_app
         app_module = import_module(app_name)
       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
         __import__(name)
       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/compat/__init__.py", line 42, in <module>
         from six.moves._thread import get_ident  # noqa
     ImportError: No module named _thread
    
    ubuntu@staging:~$ python --version
    Python 2.7.6
    
    wontfix 
    opened by joac 2
  • ImportError: cannot import name 'LocaleRegexProvider' in Django 2.0a1

    ImportError: cannot import name 'LocaleRegexProvider' in Django 2.0a1

      File "/Users/Bruno/Documents/Workspace/open-source-projects/django-surveys/.tox/py36-djangomaster/lib/python3.6/site-packages/compat/__init__.py", line 388, in <module>
        from django.urls import (
    ImportError: cannot import name 'LocaleRegexProvider'
    

    From the updates in the tests in this PR, I'm under the impression that it was renamed to RegexPattern in Django 2.0a1.

    opened by browniebroke 1
  • Support for Django 1.11 LTS

    Support for Django 1.11 LTS

    Django 1.11 LTS will be the last Django version to support Python 2. The next major release, Django 2.0, will only support Python 3.5+. So Django 1.11.x will probably be the last supported version for LTS-to-LTS support of django-compat (1.8-1.11). See Django's release notes for more.

    enhancement help wanted 
    opened by philippeowagner 1
  • GitHub project blurb doesn't mention Django 1.10

    GitHub project blurb doesn't mention Django 1.10

    This GitHub project doesn't mention Django 1.10 in the blurb:

    Screenshot

    It needs to match the README file.

    This also affects the blurb in https://djangopackages.org/packages/p/django-compat/

    opened by Flimm 1
  • FileNotFoundError: No such file or directory: README.rst

    FileNotFoundError: No such file or directory: README.rst

    $ ./bin/pip --version
    pip 8.0.2 from /webapps/planexo/lib/python3.4/site-packages (python 3.4)
    
    $ ./bin/pip install django-compat
    Collecting django-compat
      Using cached django-compat-1.0.8.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 33, in <module>
            long_description=read('README.rst')
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 17, in read
            return open(get_path(fname)).read()
        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-1wztbpt3/django-compat/README.rst'
    
        During handling of the above exception, another exception occurred:
    
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 36, in <module>
            long_description=read('README.md')
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 17, in read
            return open(get_path(fname)).read()
          File "/webapps/planexo/lib/python3.4/encodings/ascii.py", line 26, in decode
            return codecs.ascii_decode(input, self.errors)[0]
        UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 8678: ordinal not in range(128)
    
        ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-1wztbpt3/django-compat
    
    opened by SebCorbin 1
  • Test on Python 2.6, 3.2, 3.3 with supported Djangos

    Test on Python 2.6, 3.2, 3.3 with supported Djangos

    NB: This includes the Tox support added by #32

    • Fix compat.get_ident() on Python 3.2
    • Fix compat.tests.test_compat.CompatTests.test_compat() on Python 2.6
    • Fix compat.tests.test_compat.CompatTests.test_format_html() on Python 2.6

    NB: This doesn't include Python 2.5, even though it's supported by Django 1.4

    opened by moreati 1
  • Communicate supported Django version in README

    Communicate supported Django version in README

    These points should be better communicated in the README

    • [x] what version of Django is supported and unsupported anymore
    • [ ] Version convention from django-compat to Django

    Please note #17 as well that aims to show what works in wich version and if its tested.

    opened by philippeowagner 1
  • Django 2.1

    Django 2.1

    Tests fail with

      File "/home/abuild/rpmbuild/BUILD/django-compat-1.0.15/compat/tests/urls.py", line 5, in <module>
        url(r'^accounts/logout/$', views.logout, name='logout'),
    AttributeError: module 'django.contrib.auth.views' has no attribute 'logout'
    

    Fairly simple to fix https://stackoverflow.com/questions/47065438/attributeerror-module-django-contrib-auth-views-has-no-attribute

    opened by jayvdb 2
  • Add django >= 1.10 as a requirement.

    Add django >= 1.10 as a requirement.

    The lack of this creates dependency problem as provided by setup.py.

    See the following Debian bugs:

    • https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896337
    • https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896205
    opened by stylesen 1
  • URLs include for Django 2.0

    URLs include for Django 2.0

    The next version of Django is changing quite radically the way URLs are being included, by requiring an app name to be provided. One way to do it (and sometimes the only one) is to change the first parameter to a tuple.

    It would be great if there could be a version of include in django-compat. It looks like the new syntax is available from 1.9, and the old syntax is no longer working from 2.0.

    Would that be an acceptable change? I could try to put together a PR if so.

    opened by browniebroke 1
Releases(v1.0.15)
Owner
arteria GmbH
Wir machen Web.
arteria GmbH
Django project starter on steroids: quickly create a Django app AND generate source code for data models + REST/GraphQL APIs (the generated code is auto-linted and has 100% test coverage).

Create Django App ?? We're a Django project starter on steroids! One-line command to create a Django app with all the dependencies auto-installed AND

imagine.ai 68 Oct 19, 2022
A Django chatbot that is capable of doing math and searching Chinese poet online. Developed with django, channels, celery and redis.

Django Channels Websocket Chatbot A Django chatbot that is capable of doing math and searching Chinese poet online. Developed with django, channels, c

Yunbo Shi 8 Oct 28, 2022
Blog focused on skills enhancement and knowledge sharing. Tech Stack's: Vue.js, Django and Django-Ninja

Blog focused on skills enhancement and knowledge sharing. Tech Stack's: Vue.js, Django and Django-Ninja

Wanderson Fontes 2 Sep 21, 2022
Meta package to combine turbo-django and stimulus-django

Hotwire + Django This repository aims to help you integrate Hotwire with Django ?? Inspiration might be taken from @hotwired/hotwire-rails. We are sti

Hotwire for Django 31 Aug 9, 2022
django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

django-quill-editor django-quill-editor makes Quill.js easy to use on Django Forms and admin sites No configuration required for static files! The ent

lhy 139 Dec 5, 2022
A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a unique id.

Django-URL-Shortener A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a uni

Rohini Rao 3 Aug 8, 2021
Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot. A fully Django starter project.

Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot ?? Features A Django stater project with fully basic requirements for a production-ready

null 8 Jun 27, 2022
APIs for a Chat app. Written with Django Rest framework and Django channels.

ChatAPI APIs for a Chat app. Written with Django Rest framework and Django channels. The documentation for the http end points can be found here This

Victor Aderibigbe 18 Sep 9, 2022
Django-MySQL extends Django's built-in MySQL and MariaDB support their specific features not available on other databases.

Django-MySQL The dolphin-pony - proof that cute + cute = double cute. Django-MySQL extends Django's built-in MySQL and MariaDB support their specific

Adam Johnson 504 Jan 4, 2023
Django-Audiofield is a simple app that allows Audio files upload, management and conversion to different audio format (mp3, wav & ogg), which also makes it easy to play audio files into your Django application.

Django-Audiofield Description: Django Audio Management Tools Maintainer: Areski Contributors: list of contributors Django-Audiofield is a simple app t

Areski Belaid 167 Nov 10, 2022
django Filer is a file management application for django that makes handling of files and images a breeze.

django Filer is a file management application for django that makes handling of files and images a breeze.

django CMS Association 1.6k Jan 6, 2023
Bringing together django, django rest framework, and htmx

This is Just an Idea There is no code, this README just represents an idea for a minimal library that, as of now, does not exist. django-htmx-rest A l

Jack DeVries 5 Nov 24, 2022
RestApi With Django 3.2 And Django Rest Framework

RestApi-With-Django-3.2-And-Django-Rest-Framework Description This repository is a Software of Development with Python. Virtual Using pipenv, virtuale

Daniel Arturo Alejo Alvarez 6 Aug 2, 2022
A starter template for building a backend with Django and django-rest-framework using docker with PostgreSQL as the primary DB.

Django-Rest-Template! This is a basic starter template for a backend project with Django as the server and PostgreSQL as the database. About the templ

Akshat Sharma 11 Dec 6, 2022
Notes-Django: an advanced project to save notes in Django. where users are able to Create, Read, Update and Delete their notes.

An advanced software to keep you notes. It allows users to perform CRUD operations on theirs Notes. Was implemented Authorization and Authentication

Edilson Pateguana 1 Feb 5, 2022
django-reversion is an extension to the Django web framework that provides version control for model instances.

django-reversion django-reversion is an extension to the Django web framework that provides version control for model instances. Requirements Python 3

Dave Hall 2.8k Jan 2, 2023
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.

Django-environ django-environ allows you to use Twelve-factor methodology to configure your Django application with environment variables. import envi

Daniele Faraglia 2.7k Jan 7, 2023
Rosetta is a Django application that eases the translation process of your Django projects

Rosetta Rosetta is a Django application that facilitates the translation process of your Django projects. Because it doesn't export any models, Rosett

Marco Bonetti 909 Dec 26, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Feldroy 10k Dec 31, 2022