[utils.py] Errors in utils.import_attr are more understandable.
This commit is contained in:
parent
3f4a4366b3
commit
93e11befc5
@ -39,8 +39,15 @@ def import_attr(path):
|
|||||||
"""transform a python module.attr path to the attr"""
|
"""transform a python module.attr path to the attr"""
|
||||||
if not isinstance(path, str):
|
if not isinstance(path, str):
|
||||||
return string
|
return string
|
||||||
|
if "." not in path:
|
||||||
|
ValueError("%r should be of the form `module.attr` and we just got `attr`" % path)
|
||||||
module, attr = path.rsplit('.', 1)
|
module, attr = path.rsplit('.', 1)
|
||||||
|
try:
|
||||||
return getattr(import_module(module), attr)
|
return getattr(import_module(module), attr)
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError("Module %r not found" % module)
|
||||||
|
except AttributeError:
|
||||||
|
raise AttributeError("Module %r has not attribut %r" % (module, attr))
|
||||||
|
|
||||||
|
|
||||||
def redirect_params(url_name, params=None):
|
def redirect_params(url_name, params=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user