mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #10061 -- Added namespacing for named URLs - most importantly, for the admin site, where the absence of this facility was causing problems. Thanks to the many people who contributed to and helped review this patch.
This change is backwards incompatible for anyone that is using the named URLs introduced in [9739]. Any usage of the old admin_XXX names need to be modified to use the new namespaced format; in many cases this will be as simple as a search & replace for "admin_" -> "admin:". See the docs for more details on the new URL names, and the namespace resolution strategy. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11250 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -9,10 +9,11 @@ class ContextPopException(Exception):
|
||||
|
||||
class Context(object):
|
||||
"A stack container for variable context"
|
||||
def __init__(self, dict_=None, autoescape=True):
|
||||
def __init__(self, dict_=None, autoescape=True, current_app=None):
|
||||
dict_ = dict_ or {}
|
||||
self.dicts = [dict_]
|
||||
self.autoescape = autoescape
|
||||
self.current_app = current_app
|
||||
|
||||
def __repr__(self):
|
||||
return repr(self.dicts)
|
||||
@@ -96,8 +97,8 @@ class RequestContext(Context):
|
||||
Additional processors can be specified as a list of callables
|
||||
using the "processors" keyword argument.
|
||||
"""
|
||||
def __init__(self, request, dict=None, processors=None):
|
||||
Context.__init__(self, dict)
|
||||
def __init__(self, request, dict=None, processors=None, current_app=None):
|
||||
Context.__init__(self, dict, current_app=current_app)
|
||||
if processors is None:
|
||||
processors = ()
|
||||
else:
|
||||
|
||||
@@ -367,17 +367,17 @@ class URLNode(Node):
|
||||
# {% url ... as var %} construct in which cause return nothing.
|
||||
url = ''
|
||||
try:
|
||||
url = reverse(self.view_name, args=args, kwargs=kwargs)
|
||||
url = reverse(self.view_name, args=args, kwargs=kwargs, current_app=context.current_app)
|
||||
except NoReverseMatch, e:
|
||||
if settings.SETTINGS_MODULE:
|
||||
project_name = settings.SETTINGS_MODULE.split('.')[0]
|
||||
try:
|
||||
url = reverse(project_name + '.' + self.view_name,
|
||||
args=args, kwargs=kwargs)
|
||||
args=args, kwargs=kwargs, current_app=context.current_app)
|
||||
except NoReverseMatch:
|
||||
if self.asvar is None:
|
||||
# Re-raise the original exception, not the one with
|
||||
# the path relative to the project. This makes a
|
||||
# the path relative to the project. This makes a
|
||||
# better error message.
|
||||
raise e
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user