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

Related tags

Djangodjango-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
    
    [email protected]:~$ 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
This Django app will be used to host Source.Python plugins, sub-plugins, and custom packages.

Source.Python Project Manager This Django app will be used to host Source.Python plugins, sub-plugins, and custom packages. Want to help develop this

2 Sep 24, 2022
Packs a bunch of smaller CSS files together from 1 folder.

Packs a bunch of smaller CSS files together from 1 folder.

1 Dec 09, 2021
Management commands to help backup and restore your project database and media files

Django Database Backup This Django application provides management commands to help backup and restore your project database and media files with vari

687 Jan 04, 2023
Send push notifications to mobile devices through GCM or APNS in Django.

django-push-notifications A minimal Django app that implements Device models that can send messages through APNS, FCM/GCM and WNS. The app implements

Jazzband 2k Dec 26, 2022
Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Oscar Y Chen 68 Jan 07, 2023
GameStop clone with Django

GameStop clone with Django This is my side project with GameStop clone Author: HackerApe GitHub Profile: View Profile LinkedIn Profile: View Profile

Dmitriy Shin 2 Dec 26, 2021
The friendly PIL fork (Python Imaging Library)

Pillow Python Imaging Library (Fork) Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lund

Pillow 10.4k Jan 03, 2023
The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango.

The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango. It requires a django-leaflet package.

Vsevolod Novikov 33 Nov 11, 2022
Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 01, 2023
Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets).

Django Mobile Detector Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets). It uses the User-Agent string c

Botir 6 Aug 31, 2022
Simple yet powerful and really extendable application for managing a blog within your Django Web site.

Django Blog Zinnia Simple yet powerful and really extendable application for managing a blog within your Django Web site. Zinnia has been made for pub

Julien Fache 2.1k Dec 24, 2022
Django + NextJS + Tailwind Boilerplate

django + NextJS + Tailwind Boilerplate About A Django project boilerplate/templa

Shayan Debroy 3 Mar 11, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
📊📈 Serves up Pandas dataframes via the Django REST Framework for use in client-side (i.e. d3.js) visualizations and offline analysis (e.g. Excel)

Django REST Pandas Django REST Framework + pandas = A Model-driven Visualization API Django REST Pandas (DRP) provides a simple way to generate and se

wq framework 1.2k Jan 01, 2023
https://django-storages.readthedocs.io/

Installation Installing from PyPI is as easy as doing: pip install django-storages If you'd prefer to install from source (maybe there is a bugfix in

Josh Schneier 2.3k Jan 06, 2023
ProjectManagementWebsite - Project management website for CMSC495 built using the Django stack

ProjectManagementWebsite A minimal project management website for CMSC495 built

Justin 1 May 23, 2022
Redia Cache implementation in django.

django-redis Recipe APP Simple Recipe app which shows different kinds off recipe to the user. Why Cache ? Accessing data from cache is much faster tha

Avinash Alanjkar 1 Sep 21, 2022
Django Course Project - TextCorrector

Django-TextUtils Django Course Project A tool for analyzing text data in Django backend. It is a project where you can do some of the things with you

1 Oct 29, 2021
This is raw connection between redis server and django python app

Django_Redis This repository contains the code for this blogpost. Running the Application Clone the repository git clone https://github.com/xxl4tomxu9

Tom Xu 1 Sep 15, 2022
Realworld - Realworld using Django and HTMX

Realworld - Realworld using Django and HTMX

Dan Jacob 53 Jan 05, 2023