Ticket #66: app_root.diff
File app_root.diff, 2.6 KB (added by , 19 years ago) |
---|
-
django/core/urlresolvers.py
29 29 self.callback = callback 30 30 self.default_args = default_args or {} 31 31 32 def resolve(self, path ):32 def resolve(self, path, app_root = ''): 33 33 match = self.regex.search(path) 34 34 if match: 35 35 # If there are any named groups, use those as kwargs, ignoring … … 44 44 kwargs.update(self.default_args) 45 45 46 46 try: # Lazily load self.func. 47 return self.func, args, kwargs 47 return self.func, args, kwargs, app_root 48 48 except AttributeError: 49 49 self.func = self.get_callback() 50 return self.func, args, kwargs 50 return self.func, args, kwargs, app_root 51 51 52 52 def get_callback(self): 53 53 mod_name, func_name = get_mod_func(self.callback) … … 65 65 self.regex = re.compile(regex) 66 66 self.urlconf_name = urlconf_name 67 67 68 def resolve(self, path ):68 def resolve(self, path, app_root=''): 69 69 tried = [] 70 70 match = self.regex.search(path) 71 71 if match: 72 72 new_path = path[match.end():] 73 73 for pattern in self.urlconf_module.urlpatterns: 74 74 try: 75 sub_match = pattern.resolve(new_path )75 sub_match = pattern.resolve(new_path, app_root + match.group(0)) 76 76 except Resolver404, e: 77 77 tried.extend([(pattern.regex.pattern + ' ' + t) for t in e.args[0]['tried']]) 78 78 else: 79 79 if sub_match: 80 return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2]) 80 return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2]), sub_match[3] 81 81 tried.append(pattern.regex.pattern) 82 82 raise Resolver404, {'tried': tried, 'path': new_path} 83 83 -
django/core/handlers/base.py
61 61 62 62 resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF) 63 63 try: 64 callback, callback_args, callback_kwargs = resolver.resolve(path) 64 callback, callback_args, callback_kwargs, app_root = resolver.resolve(path) 65 request.app_root = app_root 65 66 66 67 # Apply view middleware 67 68 for middleware_method in self._view_middleware: