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
Analytics services for Django projects

django-analytical The django-analytical application integrates analytics services into a Django project. Using an analytics service with a Django proj

Jazzband 1.1k Dec 31, 2022
Django based webapp pulling in crypto news and price data via api

Deploy Django in Production FTA project implementing containerization of Django Web Framework into Docker to be placed into Azure Container Services a

0 Sep 21, 2022
A quick way to add React components to your Django templates.

Django-React-Templatetags This django library allows you to add React (16+) components into your django templates. Features Include react components u

Fröjd Agency 408 Jan 08, 2023
A Django Demo Project of Students Management System

Django_StudentMS A Django Demo Project of Students Management System. From NWPU Seddon for DB Class Pre. Seddon simplify the code in 2021/10/17. Hope

2 Dec 08, 2021
Show how the redis works with Python (Django).

Redis Leaderboard Python (Django) Show how the redis works with Python (Django). Try it out deploying on Heroku (See notes: How to run on Google Cloud

Tom Xu 4 Nov 16, 2021
Generate generic activity streams from the actions on your site. Users can follow any actors' activities for personalized streams.

Django Activity Stream What is Django Activity Stream? Django Activity Stream is a way of creating activities generated by the actions on your site. I

Justin Quick 2.1k Dec 29, 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 09, 2022
Automatically deletes old file for FileField and ImageField. It also deletes files on models instance deletion.

Django Cleanup Features The django-cleanup app automatically deletes files for FileField, ImageField and subclasses. When a FileField's value is chang

Ilya Shalyapin 838 Dec 30, 2022
Domain-driven e-commerce for Django

Domain-driven e-commerce for Django Oscar is an e-commerce framework for Django designed for building domain-driven sites. It is structured such that

Oscar 5.6k Jan 01, 2023
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
The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

django-crispy-forms The best way to have Django DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered

4.6k Jan 07, 2023
Projeto Crud Django and Mongo

Projeto-Crud_Django_and_Mongo Configuração para rodar o projeto Download Project

Samuel Fernandes Oliveira 2 Jan 24, 2022
A reusable Django app that configures your project for deployment

django-simple-deploy This app gives you a management command that configures your project for an initial deployment. It targets Heroku at the moment,

Eric Matthes 205 Dec 26, 2022
It's the assignment 1 from the Python 2 course, that requires a ToDoApp with authentication using Django

It's the assignment 1 from the Python 2 course, that requires a ToDoApp with authentication using Django

0 Jan 20, 2022
Basic Form Web Development using Python, Django and CSS

thebookrain Basic Form Web Development using Python, Django and CSS This is a basic project that contains two forms - borrow and donate. The form data

Ananya Dhulipala 1 Nov 27, 2021
Django + Next.js integration

Django Next.js Django + Next.js integration From a comment on StackOverflow: Run 2 ports on the same server. One for django (public facing) and one fo

Quera 162 Jan 03, 2023
django CMS Association 1.6k Jan 06, 2023
Python port of Google's libphonenumber

phonenumbers Python Library This is a Python port of Google's libphonenumber library It supports Python 2.5-2.7 and Python 3.x (in the same codebase,

David Drysdale 3.1k Jan 08, 2023
Django API creation with signed requests utilizing forms for validation.

django-formapi Create JSON API:s with HMAC authentication and Django form-validation. Version compatibility See Travis-CI page for actual test results

5 Monkeys 34 Apr 04, 2022
A simple app that provides django integration for RQ (Redis Queue)

Django-RQ Django integration with RQ, a Redis based Python queuing library. Django-RQ is a simple app that allows you to configure your queues in djan

RQ 1.6k Jan 06, 2023