Hello!

Not that I have a vote, but I do have an idea...

Ken Arnold wrote:
5. Variable lookups, and everything else, never cause render() to
fail, but insert an easy-to-catch and easy-to-bypass error string in
the output.
<snip>

Thoughts?

Another option for easy-to-catch and easy-to-bypass error string display would be to add error strings to a list on the fly (save them for a bit later). The template errors/warnings are not reported by default. To get to the errors, you would use a tag, maybe something like: {% display_errors %} Another behavior is that it could spit out the errors at the end of the document generated by the template-- maybe when DEBUG=True? This creates malformed documents in some cases, but many browsers can/will display the text anyway.

I could have a template something like this:
<html><head><title>{{ page.title }}</title></head>
<body>
Welcome to my site, {{ user.first_name }}!
<div class="errors">{% display_errors %}</div>
</body>
</html>

that generates a document like this:

<html><head><title></title></head>
<body>
Welcome to my site, !
<div class="errors">Warning: page.title is undefined on line 1 of index.thtml
Warning: user.first_name is undefined on line 3 of index.thtml</div>
</body>
</html>

My guess that the problem with this implementation is that it'd have to make two passes to output all the errors that display_errors has to list. It'd be silly to only report errors that happen before the tag occurs.

Of course some optimizations could be made so that display_errors could look like: display_errors.as_html, or display_errors.only_debug (to only display them when DEBUG=True), etc...

Thanks!

Jeff Anderson

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to