mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #24127 -- Changed the default current_app to the current namespace.
Changed the url template tag to use request.resolver_match.namespace as a default for the current_app argument if request.current_app is not set.
This commit is contained in:
committed by
Tim Graham
parent
6024fd5dc2
commit
bc7923beff
@@ -152,6 +152,10 @@ class Context(BaseContext):
|
||||
def current_app(self):
|
||||
return None if self._current_app is _current_app_undefined else self._current_app
|
||||
|
||||
@property
|
||||
def is_current_app_set(self):
|
||||
return self._current_app is not _current_app_undefined
|
||||
|
||||
@contextmanager
|
||||
def bind_template(self, template):
|
||||
if self.template is not None:
|
||||
|
||||
@@ -479,9 +479,16 @@ class URLNode(Node):
|
||||
try:
|
||||
current_app = context.request.current_app
|
||||
except AttributeError:
|
||||
# Change the fallback value to None when the deprecation path for
|
||||
# Leave only the else block when the deprecation path for
|
||||
# Context.current_app completes in Django 1.10.
|
||||
current_app = context.current_app
|
||||
# Can also remove the Context.is_current_app_set property.
|
||||
if context.is_current_app_set:
|
||||
current_app = context.current_app
|
||||
else:
|
||||
try:
|
||||
current_app = context.request.resolver_match.namespace
|
||||
except AttributeError:
|
||||
current_app = None
|
||||
|
||||
# Try to look up the URL twice: once given the view name, and again
|
||||
# relative to what we guess is the "main" app. If they both fail,
|
||||
|
||||
Reference in New Issue
Block a user