summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 04:34:34 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 04:34:34 +0000
commita5802b35ddc599f8425b1759148ca2ebc5f32837 (patch)
tree26e4ce39904d32eda090a36adbff5f12b9cc6ff3 /django
parent14161dba6b8ef496b77561eecca8cbd59323931e (diff)
Fixed #4453 -- Allow dots in URL pattern names (although the string in that case is first tried as an import path and only then falls back to being treated as a pattern).
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5530 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/urlresolvers.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 6ac406c907..a7c686aec5 100644
--- a/django/core/urlresolvers.py
+++ b/django/core/urlresolvers.py
@@ -27,11 +27,24 @@ class NoReverseMatch(Exception):
# Don't make this raise an error when used in a template.
silent_variable_failure = True
-def get_callable(lookup_view):
+def get_callable(lookup_view, can_fail=False):
+ """
+ Convert a string version of a function name to the callable object.
+
+ If the lookup_view is not an import path, it is assumed to be a URL pattern
+ label and the original string is returned.
+
+ If can_fail is True, lookup_view might be a URL pattern label, so errors
+ during the import fail and the string is returned.
+ """
if not callable(lookup_view):
mod_name, func_name = get_mod_func(lookup_view)
- if func_name != '':
- lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
+ try:
+ if func_name != '':
+ lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
+ except (ImportError, AttributeError):
+ if not can_fail:
+ raise
return lookup_view
get_callable = memoize(get_callable, _callable_cache)
@@ -248,7 +261,7 @@ class RegexURLResolver(object):
def reverse(self, lookup_view, *args, **kwargs):
try:
- lookup_view = get_callable(lookup_view)
+ lookup_view = get_callable(lookup_view, True)
except (ImportError, AttributeError):
raise NoReverseMatch
if lookup_view in self.reverse_dict: