mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #22218 -- Removed conf.urls.patterns() per deprecation timeline.
This commit is contained in:
@@ -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()
|
||||
--------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user