mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #21927 -- Made application and instance namespaces more distinct.
Made URL application namespaces be set in the included URLconf and instance namespaces in the call to include(). Deprecated other ways to set application and instance namespaces.
This commit is contained in:
committed by
Tim Graham
parent
39937de7e6
commit
1e82094f1b
@@ -1,20 +1,7 @@
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
class URLObject(object):
|
||||
def __init__(self, app_name, namespace):
|
||||
self.app_name = app_name
|
||||
self.namespace = namespace
|
||||
|
||||
def urls(self):
|
||||
return ([
|
||||
url(r'^inner/$', views.empty_view, name='urlobject-view'),
|
||||
url(r'^inner/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.empty_view, name='urlobject-view'),
|
||||
url(r'^inner/\+\\\$\*/$', views.empty_view, name='urlobject-special-view'),
|
||||
], self.app_name, self.namespace)
|
||||
urls = property(urls)
|
||||
from .tests import URLObject
|
||||
|
||||
testobj1 = URLObject('testapp', 'test-ns1')
|
||||
testobj2 = URLObject('testapp', 'test-ns2')
|
||||
@@ -23,6 +10,8 @@ default_testobj = URLObject('testapp', 'testapp')
|
||||
otherobj1 = URLObject('nodefault', 'other-ns1')
|
||||
otherobj2 = URLObject('nodefault', 'other-ns2')
|
||||
|
||||
newappobj1 = URLObject('newapp')
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^normal/$', views.empty_view, name='normal-view'),
|
||||
url(r'^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$', views.empty_view, name='normal-view'),
|
||||
@@ -45,6 +34,12 @@ urlpatterns = [
|
||||
url(r'^other1/', include(otherobj1.urls)),
|
||||
url(r'^other[246]/', include(otherobj2.urls)),
|
||||
|
||||
url(r'^newapp1/', include(newappobj1.app_urls, 'new-ns1')),
|
||||
url(r'^new-default/', include(newappobj1.app_urls)),
|
||||
|
||||
url(r'^app-included[135]/', include('urlpatterns_reverse.included_app_urls', namespace='app-ns1')),
|
||||
url(r'^app-included2/', include('urlpatterns_reverse.included_app_urls', namespace='app-ns2')),
|
||||
|
||||
url(r'^ns-included[135]/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns1')),
|
||||
url(r'^ns-included2/', include('urlpatterns_reverse.included_namespace_urls', namespace='inc-ns2')),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user