mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #23276 -- Deprecated passing views as strings to url().
This commit is contained in:
parent
2003cb23d4
commit
a9fd740d22
28 changed files with 207 additions and 182 deletions
|
@ -1100,22 +1100,25 @@ prepend the current active language code to all url patterns defined within
|
|||
from django.conf.urls import include, url
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
|
||||
from about import views as about_views
|
||||
from news import views as news_views
|
||||
from sitemap.views imort sitemap
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^sitemap\.xml$', 'sitemap.view', name='sitemap_xml'),
|
||||
url(r'^sitemap\.xml$', sitemap, name='sitemap_xml'),
|
||||
]
|
||||
|
||||
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'),
|
||||
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(
|
||||
url(r'^about/$', 'about.view', name='about'),
|
||||
url(r'^about/$', about_views.main, name='about'),
|
||||
url(r'^news/', include(news_patterns, namespace='news')),
|
||||
)
|
||||
|
||||
|
||||
After defining these URL patterns, Django will automatically add the
|
||||
language prefix to the URL patterns that were added by the ``i18n_patterns``
|
||||
function. Example::
|
||||
|
@ -1155,22 +1158,25 @@ URL patterns can also be marked translatable using the
|
|||
from django.conf.urls.i18n import i18n_patterns
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from about import views as about_views
|
||||
from news import views as news_views
|
||||
from sitemaps.views import sitemap
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^sitemap\.xml$', 'sitemap.view', name='sitemap_xml'),
|
||||
url(r'^sitemap\.xml$', sitemap, name='sitemap_xml'),
|
||||
]
|
||||
|
||||
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'),
|
||||
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(
|
||||
url(_(r'^about/$'), 'about.view', name='about'),
|
||||
url(_(r'^about/$'), about_views.main, name='about'),
|
||||
url(_(r'^news/'), include(news_patterns, namespace='news')),
|
||||
)
|
||||
|
||||
|
||||
After you've created the translations, the
|
||||
:func:`~django.core.urlresolvers.reverse` function will return the URL in the
|
||||
active language. Example::
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue