1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Refs #22218 -- Removed conf.urls.patterns() per deprecation timeline.

This commit is contained in:
Tim Graham
2015-08-17 10:45:00 -04:00
parent 3f50dc2be5
commit a25d3ce007
10 changed files with 94 additions and 230 deletions

View File

@@ -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` .

View File

@@ -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()
--------

View File

@@ -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.

View File

@@ -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