Django

Code

Show
Ignore:
Timestamp:
08/28/08 14:05:14 (3 months ago)
Author:
jacob
Message:

Fixed #8221: added some better NoReverseMatch error strings. Thanks, mrts.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/urlresolvers.py

    r8664 r8672  
    5353            if func_name != '': 
    5454                lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 
     55                if not callable(lookup_view): 
     56                    raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name)) 
    5557        except (ImportError, AttributeError): 
    5658            if not can_fail: 
     
    197199        try: 
    198200            lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 
    199         except (ImportError, AttributeError): 
    200             raise NoReverseMatch 
     201        except ImportError, e: 
     202            raise NoReverseMatch("Could not import '%s': %s" % (mod_name, e)) 
     203        except AttributeError, e: 
     204            raise NoReverseMatch("'%s' has no attribute '%s'" % (mod_name, func_name)) 
    201205        if lookup_view != self.callback: 
    202             raise NoReverseMatch 
     206            raise NoReverseMatch("Reversed view '%s' doesn't match the expected callback ('%s')." % (viewname, self.callback)) 
    203207        return self.reverse_helper(*args, **kwargs) 
    204208 
     
    280284        try: 
    281285            lookup_view = get_callable(lookup_view, True) 
    282         except (ImportError, AttributeError)
    283             raise NoReverseMatch("'%s' is not a callable." % lookup_view
     286        except (ImportError, AttributeError), e
     287            raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e)
    284288        if lookup_view in self.reverse_dict: 
    285289            return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]]) 
    286         raise NoReverseMatch("Reverse for '%s' not found." % lookup_view) 
     290        raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword " 
     291                "arguments '%s' not found." % (lookup_view, args, kwargs)) 
    287292 
    288293    def reverse_helper(self, lookup_view, *args, **kwargs):