tickets_full: 3349

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
3349 2007-01-22 20:08:02 2011-09-28 16:12:27 2019-06-24 00:50:55.259503 Accepted closed Template system     master fixed If an ImportError occurs within some loaders a rather confusing exception is raised. The problem is, when Django attempts to load a custom tag library (in source:django/trunk/django/template/__init__.py, in the {{{get_library()}}} function), it ''traps'' all {{{ImportError}}}'s, regardless of where they are ''thrown'' from: {{{ try: mod = __import__(module_name, {}, {}, ['']) except ImportError, e: raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e) }}} An example... If I have a "view" like so: {{{ def my_view(request): return render_to_response('my.tpl', {}) }}} ...And a corresponding template: {{{ {% load tag_lib %} <h1>my template</h1> ... }}} ...Now, here's the tag library {{{tag_lib}}}: {{{ import notthere ... }}} ...Invoking our view, now, will yield a not-very-easy-to-understand (unless you already know the problem) error message: {{{ TemplateSyntaxError at /my_view 'tag_lib' is not a valid tag library: Could not load template library from django.templatetags.tag_lib, No module named notthere Request Method: GET Request URL: http://localhost:8000/my_view Exception Type: TemplateSyntaxError Exception Value: 'tag_lib' is not a valid tag library: Could not load template library from django.templatetags.tag_lib, No module named notthere Exception Location: /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/template/defaulttags.py in load, line 692 }}} You may need to look closely to notice that the root of the problem was that our tag library tried to load a module {{{notthere}}}; the problem ''was not'' that we tried to load a non-existant tag library. This is essentially the same message that you will get when trying to load a tag library that is completely non-existant - i.e., if our template were: {{{ {% load not_tag_lib %} <h1>my template</h1> ... }}} We would now see the error message: {{{ TemplateSyntaxError at /my_view 'not_tag_lib' is not a valid tag library: Could not load template library from django.templatetags.not_tag_lib, No module named not_tag_lib ... }}} The type of error message that I would like to see would be one that is not obfuscated and wrapped in a {{{TemplateSyntaxError}}} exception. Such a useful error message ''will'' be displayed if some other problem occurs in our tag library; for instance, if our tag library looks like {{{ blablabla ... }}} then we will be greeted with the slightly-more-decipherable error message, {{{ NameError at /my_view name 'blablabla' is not defined Request Method: GET Request URL: http://localhost:8000/my_view Exception Type: NameError Exception Value: name 'blablabla' is not defined Exception Location: /usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/template/__init__.py in get_library, line 880 }}} I'm not certain that there's a way around this (I'm relatively new to Python), but I suspect it is possible to resolve by (somehow) determining which file/line the ImportError originated from/on, and adjusting the error message that is raised in the {{{get_library()}}} function. I'd be willing to spend time on a patch if I you're all willing to accept one. :) nobody Chris Wagner <cw264701@ohiou.edu>   0 1 0 1 0 0
Powered by Datasette · Query took 2.571ms