mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #22218 -- Deprecated django.conf.urls.patterns.
Thanks Carl Meyer for the suggestion and Alex Gaynor and Carl for reviews.
This commit is contained in:
parent
e6ced2bb08
commit
d73d0e071c
117 changed files with 1180 additions and 1099 deletions
|
@ -911,13 +911,15 @@ URL. Paths listed in :setting:`LOCALE_PATHS` are also included.
|
|||
|
||||
You hook it up like this::
|
||||
|
||||
from django.views.i18n import javascript_catalog
|
||||
|
||||
js_info_dict = {
|
||||
'packages': ('your.app.package',),
|
||||
}
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
|
||||
)
|
||||
urlpatterns = [
|
||||
url(r'^jsi18n/$', javascript_catalog, js_info_dict),
|
||||
]
|
||||
|
||||
Each string in ``packages`` should be in Python dotted-package syntax (the
|
||||
same format as the strings in :setting:`INSTALLED_APPS`) and should refer to a
|
||||
|
@ -935,9 +937,9 @@ changed by altering the ``domain`` argument.
|
|||
|
||||
You can make the view dynamic by putting the packages into the URL pattern::
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
|
||||
)
|
||||
urlpatterns = [
|
||||
url(r'^jsi18n/(?P<packages>\S+?)/$', javascript_catalog),
|
||||
]
|
||||
|
||||
With this, you specify the packages as a list of package names delimited by '+'
|
||||
signs in the URL. This is especially useful if your pages use code from
|
||||
|
@ -1085,25 +1087,30 @@ Language prefix in URL patterns
|
|||
|
||||
.. function:: i18n_patterns(prefix, pattern_description, ...)
|
||||
|
||||
This function can be used in your root URLconf as a replacement for the normal
|
||||
:func:`django.conf.urls.patterns` function. Django will automatically
|
||||
.. deprecated:: 1.8
|
||||
|
||||
The ``prefix`` argument to ``i18n_patterns()`` has been deprecated and will
|
||||
not be supported in Django 2.0. Simply pass a list of
|
||||
:func:`django.conf.urls.url` instances instead.
|
||||
|
||||
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
|
||||
:func:`~django.conf.urls.i18n.i18n_patterns`. Example URL patterns::
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^sitemap\.xml$', 'sitemap.view', name='sitemap_xml'),
|
||||
)
|
||||
]
|
||||
|
||||
news_patterns = patterns('',
|
||||
news_patterns = [
|
||||
url(r'^$', 'news.views.index', name='index'),
|
||||
url(r'^category/(?P<slug>[\w-]+)/$', 'news.views.category', name='category'),
|
||||
url(r'^(?P<slug>[\w-]+)/$', 'news.views.details', name='detail'),
|
||||
)
|
||||
]
|
||||
|
||||
urlpatterns += i18n_patterns('',
|
||||
urlpatterns += i18n_patterns(
|
||||
url(r'^about/$', 'about.view', name='about'),
|
||||
url(r'^news/', include(news_patterns, namespace='news')),
|
||||
)
|
||||
|
@ -1144,21 +1151,21 @@ Translating URL patterns
|
|||
URL patterns can also be marked translatable using the
|
||||
:func:`~django.utils.translation.ugettext_lazy` function. Example::
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
urlpatterns = patterns(''
|
||||
urlpatterns = [
|
||||
url(r'^sitemap\.xml$', 'sitemap.view', name='sitemap_xml'),
|
||||
)
|
||||
]
|
||||
|
||||
news_patterns = patterns(''
|
||||
news_patterns = [
|
||||
url(r'^$', 'news.views.index', name='index'),
|
||||
url(_(r'^category/(?P<slug>[\w-]+)/$'), 'news.views.category', name='category'),
|
||||
url(r'^(?P<slug>[\w-]+)/$', 'news.views.details', name='detail'),
|
||||
)
|
||||
]
|
||||
|
||||
urlpatterns += i18n_patterns('',
|
||||
urlpatterns += i18n_patterns(
|
||||
url(_(r'^about/$'), 'about.view', name='about'),
|
||||
url(_(r'^news/'), include(news_patterns, namespace='news')),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue