From 3d02de27138b420825156f0631a32cdcda2d91aa Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 25 Jul 2006 07:30:22 +0000 Subject: [PATCH] Added resolve() and reverse() helper functions to django.core.urlresolvers git-svn-id: http://code.djangoproject.com/svn/django/trunk@3445 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/urlresolvers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index a1661a2ecd..83fffacefb 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -201,3 +201,19 @@ class RegexURLResolver(object): sub_match = self.reverse(viewname, *args, **kwargs) result = reverse_helper(self.regex, *args, **kwargs) return result + sub_match + +def resolve(path, urlconf=None): + if urlconf is None: + from django.conf import settings + urlconf = settings.ROOT_URLCONF + resolver = RegexURLResolver(r'^/', urlconf) + return resolver.resolve(path) + +def reverse(viewname, urlconf, args=None, kwargs=None): + args = args or [] + kwargs = kwargs or {} + if urlconf is None: + from django.conf import settings + urlconf = settings.ROOT_URLCONF + resolver = RegexURLResolver(r'^/', urlconf) + return resolver.reverse(viewname, *args, **kwargs)