Bugfix for issue #15900: https://code.djangoproject.com/ticket/15900.
This code is largely reproduced from https://code.djangoproject.com/browser/django/trunk/django/core/urlresolvers.py and is the work of Django’s authors: https://code.djangoproject.com/browser/django/trunk/AUTHORS
It is licensed under Django’s BSD license, available here: https://code.djangoproject.com/browser/django/trunk/LICENSE
To use, simply import this code in your project’s root URLconf file before defining any URL patterns.