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
Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in the browser cookies.

Django Persistent Filters Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in

Lorenzo Prodon 2 Aug 05, 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

10.1k Jan 08, 2023
A django integration for huey task queue that supports multi queue management

django-huey This package is an extension of huey contrib djhuey package that allows users to manage multiple queues. Installation Using pip package ma

GAIA Software 32 Nov 26, 2022
The little ASGI framework that shines. 🌟

✨ The little ASGI framework that shines. ✨ Documentation: https://www.starlette.io/ Community: https://discuss.encode.io/c/starlette Starlette Starlet

Encode 7.7k Dec 31, 2022
TinyMCE integration for Django

django-tinymce django-tinymce is a Django application that contains a widget to render a form field as a TinyMCE editor. Quickstart Install django-tin

Jazzband 1.1k Dec 26, 2022
Streamlining Django forms to provide all the wins of single-page-applications without the pain.

nango Streamlining Django forms to provide all the wins of single-page-applications without the pain. Key features Available to all Django deployments

Nick Farrell 107 Dec 12, 2022
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
A Django GraphQL (Graphene) base template

backend A Django GraphQL (Graphene) base template Make sure your IDE/Editor has Black and EditorConfig plugins installed; and configure it lint file a

Reckonsys 4 May 25, 2022
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
Updates redisearch instance with igdb data used for kimosabe

igdb-pdt Update RediSearch with IGDB games data in the following Format: { "game_slug": { "name": "game_name", "cover": "igdb_coverart_url",

6rotoms 0 Jul 30, 2021
django+bootstrap5 实现的 个人博客

项目状态: 正在开发中【目前已基本可用】 项目地址: https://github.com/find456789/django_blog django_blog django+bootstrap5 实现的 个人博客 特点 文章的历史版本管理(随时回退) rss、atom markdown 评论功能

名字 3 Nov 16, 2021
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
A simple porfolio with Django, Bootstrap and Sqlite3

Django Portofolio Example this is a basic portfolio in dark mode Installation git clone https://github.com/FaztWeb/django-portfolio-simple.git cd djan

Fazt Web 16 Sep 26, 2022
Median and percentile for Django and MongoEngine

Tailslide Median and percentile for Django and MongoEngine Supports: PostgreSQL SQLite MariaDB MySQL (with an extension) SQL Server MongoDB 🔥 Uses na

Andrew Kane 4 Jan 15, 2022
PostgreSQL with Docker + Portainer + pgAdmin + Django local

django-postgresql-docker Running PostgreSQL with Docker + Portainer + pgAdmin + Django local for development. This project was done with: Python 3.9.8

Regis Santos 4 Jun 12, 2022
Awesome Django Markdown Editor, supported for Bootstrap & Semantic-UI

martor Martor is a Markdown Editor plugin for Django, supported for Bootstrap & Semantic-UI. Features Live Preview Integrated with Ace Editor Supporte

659 Jan 04, 2023
A simple page with paypal payment and confiramtion in django

django-paypal a simple page with paypal payment and confiramtion in django Youtube Video : Paypal Smart Button : https://developer.paypal.com/demo/che

Mahmoud Ahmed 5 Feb 19, 2022
A UUIDField for Django

django-uuidfield Provides a UUIDField for your Django models. Installation Install it with pip (or easy_install): pip install django-uuidfield Usage

David Cramer 265 Nov 30, 2022
A collection of models, views, middlewares, and forms to help secure a Django project.

Django-Security This package offers a number of models, views, middlewares and forms to facilitate security hardening of Django applications. Full doc

SD Elements 258 Jan 03, 2023
REST API with Django and SQLite3

REST API with Django and SQLite3

Luis Quiñones Requelme 1 Nov 07, 2021