Ticket #8809: fix_ticket_8809_urlsresolvers_error_message.diff

File fix_ticket_8809_urlsresolvers_error_message.diff, 2.1 KB (added by v1v3kn, 13 years ago)

Changed the import line to match PEP8 standards.

  • django/core/urlresolvers.py

     
    88"""
    99
    1010import re
     11import os
    1112from threading import local
    12 
     13from imp import find_module
    1314from django.http import Http404
    1415from django.conf import settings
    1516from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
     
    7273    # Don't make this raise an error when used in a template.
    7374    silent_variable_failure = True
    7475
     76def 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
    7590def get_callable(lookup_view, can_fail=False):
    7691    """
    7792    Convert a string version of a function name to the callable object.
     
    164179            self._callback = get_callable(self._callback_str)
    165180        except ImportError, e:
    166181            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)))
    168183        except AttributeError, e:
    169184            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)))
    171186        return self._callback
    172187    callback = property(_get_callback)
    173188
Back to Top