mirror of https://github.com/django/django.git
Fixed #25610 -- Reverted removal of request.current_app in {% url %} tag.
The deprecation removal in 5e450c52aa
removed too much.
This commit is contained in:
parent
23073f9644
commit
34af2bc523
|
@ -434,9 +434,12 @@ class URLNode(Node):
|
|||
}
|
||||
view_name = self.view_name.resolve(context)
|
||||
try:
|
||||
current_app = context.request.resolver_match.namespace
|
||||
current_app = context.request.current_app
|
||||
except AttributeError:
|
||||
current_app = None
|
||||
try:
|
||||
current_app = context.request.resolver_match.namespace
|
||||
except AttributeError:
|
||||
current_app = None
|
||||
# Try to look up the URL. If it fails, raise NoReverseMatch unless the
|
||||
# {% url ... as var %} construct is used, in which case return nothing.
|
||||
url = ''
|
||||
|
|
|
@ -251,3 +251,23 @@ class UrlTagTests(SimpleTestCase):
|
|||
context = RequestContext(request)
|
||||
output = template.render(context)
|
||||
self.assertEqual(output, '/ns2/named-client/42/')
|
||||
|
||||
@setup({'url-namespace-no-current-app': '{% url "app:named.client" 42 %}'})
|
||||
def test_url_namespace_no_current_app(self):
|
||||
request = RequestFactory().get('/')
|
||||
request.resolver_match = resolve('/ns1/')
|
||||
request.current_app = None
|
||||
template = self.engine.get_template('url-namespace-no-current-app')
|
||||
context = RequestContext(request)
|
||||
output = template.render(context)
|
||||
self.assertEqual(output, '/ns2/named-client/42/')
|
||||
|
||||
@setup({'url-namespace-explicit-current-app': '{% url "app:named.client" 42 %}'})
|
||||
def test_url_namespace_explicit_current_app(self):
|
||||
request = RequestFactory().get('/')
|
||||
request.resolver_match = resolve('/ns1/')
|
||||
request.current_app = 'app'
|
||||
template = self.engine.get_template('url-namespace-explicit-current-app')
|
||||
context = RequestContext(request)
|
||||
output = template.render(context)
|
||||
self.assertEqual(output, '/ns2/named-client/42/')
|
||||
|
|
Loading…
Reference in New Issue