Ticket #8809: django8809-urlerror.diff

File django8809-urlerror.diff, 2.4 KB (added by bpeschier, 4 years ago)
  • conf/urls/defaults.py

     
     1from django.conf import settings
    12from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    23from django.core.exceptions import ImproperlyConfigured
    34
     
    2526        elif isinstance(t, RegexURLPattern):
    2627            t.add_prefix(prefix)
    2728        pattern_list.append(t)
     29    if settings.DEBUG:
     30        # Load up debug information on pattern-origin
     31        import inspect
     32        import os.path
     33        current_frame = inspect.currentframe()
     34        if current_frame: # currentframe not always supported
     35            calling_frame = inspect.getouterframes(current_frame)[1]
     36            origin  = (calling_frame[4], os.path.normpath(calling_frame[1]), calling_frame[2], )
     37            for pattern in pattern_list:
     38                pattern._origin = origin
    2839    return pattern_list
    2940
    3041def url(regex, view, kwargs=None, name=None, prefix=''):
  • core/urlresolvers.py

     
    162162            return self._callback
    163163        try:
    164164            self._callback = get_callable(self._callback_str)
    165         except ImportError, e:
    166             mod_name, _ = get_mod_func(self._callback_str)
    167             raise ViewDoesNotExist("Could not import %s. Error was: %s" % (mod_name, str(e)))
    168         except AttributeError, e:
     165        except (ImportError, AttributeError), e:
    169166            mod_name, func_name = get_mod_func(self._callback_str)
    170             raise ViewDoesNotExist("Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e)))
     167            debug_info = ''
     168            if settings.DEBUG and hasattr(self, '_origin'): # extra debug info available
     169                debug_info = ' from pattern "%s" at %s:%s' % self._origin
     170            if isinstance(e, ImportError):
     171                raise ViewDoesNotExist("Could not import %s%s. Error was: %s" % (mod_name, debug_info, str(e)))
     172            elif isinstance(e, AttributeError):
     173                raise ViewDoesNotExist("Tried %s in module %s%s. Error was: %s" % (func_name, mod_name, debug_info, str(e)))
    171174        return self._callback
    172175    callback = property(_get_callback)
    173176
Back to Top