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
This commit is contained in:
Adrian Holovaty 2006-07-25 07:30:22 +00:00
parent e5c40514fb
commit 3d02de2713
1 changed files with 16 additions and 0 deletions

View File

@ -201,3 +201,19 @@ class RegexURLResolver(object):
sub_match = self.reverse(viewname, *args, **kwargs) sub_match = self.reverse(viewname, *args, **kwargs)
result = reverse_helper(self.regex, *args, **kwargs) result = reverse_helper(self.regex, *args, **kwargs)
return result + sub_match 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)