Ticket #8809: fix_ticket_8809_urlsresolvers_error_message.diff
File fix_ticket_8809_urlsresolvers_error_message.diff, 2.1 KB (added by , 14 years ago) |
---|
-
django/core/urlresolvers.py
8 8 """ 9 9 10 10 import re 11 import os 11 12 from threading import local 12 13 from imp import find_module 13 14 from django.http import Http404 14 15 from django.conf import settings 15 16 from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist … … 72 73 # Don't make this raise an error when used in a template. 73 74 silent_variable_failure = True 74 75 76 def view_not_found_error(mod_name, view): 77 # If a view is not found, this function searches for the urls.py file and line from 78 # which the error originated. 79 80 urls_file_path = find_module(mod_name)[1] + '/urls.py' # Path of the urls.py file where the error is 81 view_not_found = '' 82 if os.path.isfile(urls_file_path): 83 f = open(urls_file_path) 84 for n,line in enumerate(f): 85 if line.find(view) != -1: 86 view_not_found = "\nError occurred in %s at line %d:\n\"%s\"" % (urls_file_path,n,line) 87 return view_not_found 88 89 75 90 def get_callable(lookup_view, can_fail=False): 76 91 """ 77 92 Convert a string version of a function name to the callable object. … … 164 179 self._callback = get_callable(self._callback_str) 165 180 except ImportError, e: 166 181 mod_name, _ = get_mod_func(self._callback_str) 167 raise ViewDoesNotExist("Could not import %s. Error was: %s " % (mod_name, str(e)))182 raise ViewDoesNotExist("Could not import %s. Error was: %s.\n%s" % (mod_name, str(e),view_not_found_error(mod_name, self._callback_str))) 168 183 except AttributeError, e: 169 184 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)))185 raise ViewDoesNotExist("Tried %s in module %s. Error was: %s.\n%s" % (func_name, mod_name, str(e),view_not_found_error(mod_name, self._callback_str))) 171 186 return self._callback 172 187 callback = property(_get_callback) 173 188