Refs #22218 -- Removed conf.urls.patterns() per deprecation timeline.
This commit is contained in:
parent
3f50dc2be5
commit
a25d3ce007
|
@ -10,7 +10,7 @@ from django.utils.deprecation import (
|
|||
RemovedInDjango20Warning, RemovedInDjango110Warning,
|
||||
)
|
||||
|
||||
__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'patterns', 'url']
|
||||
__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url']
|
||||
|
||||
handler400 = 'django.views.defaults.bad_request'
|
||||
handler403 = 'django.views.defaults.permission_denied'
|
||||
|
@ -76,23 +76,6 @@ def include(arg, namespace=None, app_name=None):
|
|||
return (urlconf_module, app_name, namespace)
|
||||
|
||||
|
||||
def patterns(prefix, *args):
|
||||
warnings.warn(
|
||||
'django.conf.urls.patterns() is deprecated and will be removed in '
|
||||
'Django 1.10. Update your urlpatterns to be a list of '
|
||||
'django.conf.urls.url() instances instead.',
|
||||
RemovedInDjango110Warning, stacklevel=2
|
||||
)
|
||||
pattern_list = []
|
||||
for t in args:
|
||||
if isinstance(t, (list, tuple)):
|
||||
t = url(prefix=prefix, *t)
|
||||
elif isinstance(t, RegexURLPattern):
|
||||
t.add_prefix(prefix)
|
||||
pattern_list.append(t)
|
||||
return pattern_list
|
||||
|
||||
|
||||
def url(regex, view, kwargs=None, name=None, prefix=''):
|
||||
if isinstance(view, (list, tuple)):
|
||||
# For include(...) processing.
|
||||
|
|
|
@ -1,33 +1,18 @@
|
|||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import patterns, url
|
||||
from django.conf.urls import url
|
||||
from django.core.urlresolvers import LocaleRegexURLResolver
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango110Warning
|
||||
from django.views.i18n import set_language
|
||||
|
||||
|
||||
def i18n_patterns(prefix, *args):
|
||||
def i18n_patterns(*urls):
|
||||
"""
|
||||
Adds the language code prefix to every URL pattern within this
|
||||
function. This may only be used in the root URLconf, not in an included
|
||||
URLconf.
|
||||
"""
|
||||
if isinstance(prefix, six.string_types):
|
||||
warnings.warn(
|
||||
"Calling i18n_patterns() with the `prefix` argument and with tuples "
|
||||
"instead of django.conf.urls.url() instances is deprecated and "
|
||||
"will no longer work in Django 1.10. Use a list of "
|
||||
"django.conf.urls.url() instances instead.",
|
||||
RemovedInDjango110Warning, stacklevel=2
|
||||
)
|
||||
pattern_list = patterns(prefix, *args)
|
||||
else:
|
||||
pattern_list = [prefix] + list(args)
|
||||
if not settings.USE_I18N:
|
||||
return pattern_list
|
||||
return [LocaleRegexURLResolver(pattern_list)]
|
||||
return urls
|
||||
return [LocaleRegexURLResolver(list(urls))]
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
|
|
@ -223,14 +223,6 @@ class RegexURLPattern(LocaleRegexProvider):
|
|||
def __repr__(self):
|
||||
return force_str('<%s %s %s>' % (self.__class__.__name__, self.name, self.regex.pattern))
|
||||
|
||||
def add_prefix(self, prefix):
|
||||
"""
|
||||
Adds the prefix string to a string-based callback.
|
||||
"""
|
||||
if not prefix or not hasattr(self, '_callback_str'):
|
||||
return
|
||||
self._callback_str = prefix + '.' + self._callback_str
|
||||
|
||||
def resolve(self, path):
|
||||
match = self.regex.search(path)
|
||||
if match:
|
||||
|
|
|
@ -626,7 +626,7 @@ details on these changes.
|
|||
:mod:`django.contrib.gis.utils` will be removed.
|
||||
|
||||
* ``django.conf.urls.defaults`` will be removed. The functions
|
||||
:func:`~django.conf.urls.include`, :func:`~django.conf.urls.patterns` and
|
||||
:func:`~django.conf.urls.include`, ``patterns()`` and
|
||||
:func:`~django.conf.urls.url` plus :data:`~django.conf.urls.handler404`,
|
||||
:data:`~django.conf.urls.handler500`, are now available through
|
||||
:mod:`django.conf.urls` .
|
||||
|
|
|
@ -4,77 +4,6 @@
|
|||
|
||||
.. module:: django.conf.urls
|
||||
|
||||
patterns()
|
||||
----------
|
||||
|
||||
.. function:: patterns(prefix, pattern_description, ...)
|
||||
|
||||
.. deprecated:: 1.8
|
||||
|
||||
``urlpatterns`` should be a plain list of :func:`django.conf.urls.url`
|
||||
instances instead.
|
||||
|
||||
A function that takes a prefix, and an arbitrary number of URL patterns, and
|
||||
returns a list of URL patterns in the format Django needs.
|
||||
|
||||
The first argument to ``patterns()`` is a string ``prefix``. Here's the example
|
||||
URLconf from the :doc:`Django overview </intro/overview>`::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^articles/([0-9]{4})/$', 'news.views.year_archive'),
|
||||
url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'news.views.month_archive'),
|
||||
url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'news.views.article_detail'),
|
||||
)
|
||||
|
||||
In this example, each view has a common prefix -- ``'news.views'``.
|
||||
Instead of typing that out for each entry in ``urlpatterns``, you can use the
|
||||
first argument to the ``patterns()`` function to specify a prefix to apply to
|
||||
each view function.
|
||||
|
||||
With this in mind, the above example can be written more concisely as::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
urlpatterns = patterns('news.views',
|
||||
url(r'^articles/([0-9]{4})/$', 'year_archive'),
|
||||
url(r'^articles/([0-9]{4})/([0-9]{2})/$', 'month_archive'),
|
||||
url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 'article_detail'),
|
||||
)
|
||||
|
||||
Note that you don't put a trailing dot (``"."``) in the prefix. Django puts
|
||||
that in automatically.
|
||||
|
||||
The remaining arguments should be tuples in this format::
|
||||
|
||||
(regular expression, Python callback function [, optional_dictionary [, optional_name]])
|
||||
|
||||
The ``optional_dictionary`` and ``optional_name`` parameters are described in
|
||||
:ref:`Passing extra options to view functions <views-extra-options>`.
|
||||
|
||||
.. note::
|
||||
Because ``patterns()`` is a function call, it accepts a maximum of 255
|
||||
arguments (URL patterns, in this case). This is a limit for all Python
|
||||
function calls. This is rarely a problem in practice, because you'll
|
||||
typically structure your URL patterns modularly by using ``include()``
|
||||
sections. However, on the off-chance you do hit the 255-argument limit,
|
||||
realize that ``patterns()`` returns a Python list, so you can split up the
|
||||
construction of the list.
|
||||
|
||||
::
|
||||
|
||||
urlpatterns = patterns('',
|
||||
...
|
||||
)
|
||||
urlpatterns += patterns('',
|
||||
...
|
||||
)
|
||||
|
||||
Python lists have unlimited size, so there's no limit to how many URL
|
||||
patterns you can construct. The only limit is that you can only create 254
|
||||
at a time (the 255th argument is the initial prefix argument).
|
||||
|
||||
static()
|
||||
--------
|
||||
|
||||
|
|
|
@ -1233,7 +1233,7 @@ disable this backward-compatibility shim and deprecation warning.
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Until Django 1.3, the functions :func:`~django.conf.urls.include`,
|
||||
:func:`~django.conf.urls.patterns` and :func:`~django.conf.urls.url` plus
|
||||
``patterns()`` and :func:`~django.conf.urls.url` plus
|
||||
:data:`~django.conf.urls.handler404`, :data:`~django.conf.urls.handler500`
|
||||
were located in a ``django.conf.urls.defaults`` module.
|
||||
|
||||
|
|
|
@ -1332,13 +1332,7 @@ Django provides two mechanisms to internationalize URL patterns:
|
|||
Language prefix in URL patterns
|
||||
-------------------------------
|
||||
|
||||
.. function:: i18n_patterns(prefix, pattern_description, ...)
|
||||
|
||||
.. deprecated:: 1.8
|
||||
|
||||
The ``prefix`` argument to ``i18n_patterns()`` has been deprecated and will
|
||||
not be supported in Django 1.10. Simply pass a list of
|
||||
:func:`django.conf.urls.url` instances instead.
|
||||
.. function:: i18n_patterns(*pattern_list)
|
||||
|
||||
This function can be used in your root URLconf and Django will automatically
|
||||
prepend the current active language code to all url patterns defined within
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
from django.http import HttpResponse, StreamingHttpResponse
|
||||
from django.test import ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango110Warning
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
# test deprecated version of i18n_patterns() function (with prefix). Remove it
|
||||
# and convert to list of urls() in Django 1.10
|
||||
i18n_patterns = ignore_warnings(category=RemovedInDjango110Warning)(i18n_patterns)
|
||||
|
||||
urlpatterns = i18n_patterns('',
|
||||
(r'^simple/$', lambda r: HttpResponse()),
|
||||
(r'^streaming/$', lambda r: StreamingHttpResponse([_("Yes"), "/", _("No")])),
|
||||
urlpatterns = i18n_patterns(
|
||||
url(r'^simple/$', lambda r: HttpResponse()),
|
||||
url(r'^streaming/$', lambda r: StreamingHttpResponse([_("Yes"), "/", _("No")])),
|
||||
)
|
||||
|
|
|
@ -1,31 +1,24 @@
|
|||
import warnings
|
||||
|
||||
from django.conf.urls import include, patterns, url
|
||||
from django.utils.deprecation import RemovedInDjango110Warning
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from .namespace_urls import URLObject
|
||||
from .views import view_class_instance
|
||||
from .views import empty_view, view_class_instance
|
||||
|
||||
testobj3 = URLObject('testapp', 'test-ns3')
|
||||
testobj4 = URLObject('testapp', 'test-ns4')
|
||||
|
||||
# test deprecated patterns() function. convert to list of urls() in Django 1.10
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=RemovedInDjango110Warning)
|
||||
urlpatterns = [
|
||||
url(r'^normal/$', empty_view, name='inc-normal-view'),
|
||||
url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', empty_view, name='inc-normal-view'),
|
||||
|
||||
urlpatterns = patterns('urlpatterns_reverse.views',
|
||||
url(r'^normal/$', 'empty_view', name='inc-normal-view'),
|
||||
url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', 'empty_view', name='inc-normal-view'),
|
||||
url(r'^\+\\\$\*/$', empty_view, name='inc-special-view'),
|
||||
|
||||
url(r'^\+\\\$\*/$', 'empty_view', name='inc-special-view'),
|
||||
|
||||
url(r'^mixed_args/([0-9]+)/(?P<arg2>[0-9]+)/$', 'empty_view', name='inc-mixed-args'),
|
||||
url(r'^no_kwargs/([0-9]+)/([0-9]+)/$', 'empty_view', name='inc-no-kwargs'),
|
||||
url(r'^mixed_args/([0-9]+)/(?P<arg2>[0-9]+)/$', empty_view, name='inc-mixed-args'),
|
||||
url(r'^no_kwargs/([0-9]+)/([0-9]+)/$', empty_view, name='inc-no-kwargs'),
|
||||
|
||||
url(r'^view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', view_class_instance, name='inc-view-class'),
|
||||
|
||||
(r'^test3/', include(testobj3.urls)),
|
||||
(r'^test4/', include(testobj4.urls)),
|
||||
(r'^ns-included3/', include('urlpatterns_reverse.included_urls', namespace='inc-ns3')),
|
||||
(r'^ns-included4/', include('urlpatterns_reverse.namespace_urls', namespace='inc-ns4')),
|
||||
)
|
||||
url(r'^test3/', include(testobj3.urls)),
|
||||
url(r'^test4/', include(testobj4.urls)),
|
||||
url(r'^ns-included3/', include('urlpatterns_reverse.included_urls', namespace='inc-ns3')),
|
||||
url(r'^ns-included4/', include('urlpatterns_reverse.namespace_urls', namespace='inc-ns4')),
|
||||
]
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
import warnings
|
||||
|
||||
from django.conf.urls import include, patterns, url
|
||||
from django.utils.deprecation import RemovedInDjango110Warning
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from .views import (
|
||||
absolute_kwargs_view, defaults_view, empty_view, empty_view_partial,
|
||||
empty_view_wrapped, nested_view,
|
||||
empty_view_wrapped, kwargs_view, nested_view,
|
||||
)
|
||||
|
||||
other_patterns = [
|
||||
|
@ -13,11 +10,7 @@ other_patterns = [
|
|||
url(r'nested_path/$', nested_view),
|
||||
]
|
||||
|
||||
# test deprecated patterns() function. convert to list of urls() in Django 1.10
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=RemovedInDjango110Warning)
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^places/([0-9]+)/$', empty_view, name='places'),
|
||||
url(r'^places?/$', empty_view, name="places?"),
|
||||
url(r'^places+/$', empty_view, name="places+"),
|
||||
|
@ -75,17 +68,17 @@ with warnings.catch_warnings():
|
|||
url(r'^(?:foo|bar)(\w+)/$', empty_view, name="disjunction"),
|
||||
|
||||
# Regression views for #9038. See tests for more details
|
||||
url(r'arg_view/$', 'urlpatterns_reverse.views.kwargs_view'),
|
||||
url(r'arg_view/(?P<arg1>[0-9]+)/$', 'urlpatterns_reverse.views.kwargs_view'),
|
||||
url(r'arg_view/$', kwargs_view),
|
||||
url(r'arg_view/(?P<arg1>[0-9]+)/$', kwargs_view),
|
||||
url(r'absolute_arg_view/(?P<arg1>[0-9]+)/$', absolute_kwargs_view),
|
||||
url(r'absolute_arg_view/$', absolute_kwargs_view),
|
||||
|
||||
# Tests for #13154. Mixed syntax to test both ways of defining URLs.
|
||||
url(r'defaults_view1/(?P<arg1>[0-9]+)/', defaults_view, {'arg2': 1}, name='defaults'),
|
||||
(r'defaults_view2/(?P<arg1>[0-9]+)/', defaults_view, {'arg2': 2}, 'defaults'),
|
||||
url(r'defaults_view2/(?P<arg1>[0-9]+)/', defaults_view, {'arg2': 2}, 'defaults'),
|
||||
|
||||
url('^includes/', include(other_patterns)),
|
||||
|
||||
# Security tests
|
||||
url('(.+)/security/$', empty_view, name='security'),
|
||||
)
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue