Opened 13 years ago
Last modified 13 years ago
#339 closed enhancement (FIXED)
Let jinja throw errors on undefined variables
Reported by: | Elrond | Owned by: | Elrond |
---|---|---|---|
Priority: | trivial | Milestone: | 0.2.1 |
Component: | programming | Keywords: | |
Cc: | Parent Tickets: |
Description
(this is to discuss this and then possibly implement it. Implementing is **very** easy). Currently jinja2 replaces ``{{ not_known }}`` by the empty string. The question is, wether it would be better for it to throw an error? Rationale being: Either it's a typo, or it's an error for the variable to be referenced but not being there. Does that make sense? Enabling this: :: mediagoblin/tools/template.py: @@ -43,6 +43,7 @@ def get_jinja_env(template_loader, locale): template_env = jinja2.Environment( loader=template_loader, autoescape=True, + undefined=jinja2.StrictUndefined, extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'])
Change History (7)
comment:1 by , 13 years ago
Component: | → Programming |
---|---|
Priority: | Normal → Low |
comment:2 by , 13 years ago
jinja2 has a ``defined`` test. That should help if you have an attribute that purposefully might or might not exist. Edit: We might also conider `jinja2.DebugUndefined <http://jinja.pocoo.org/docs/api/#jinja2.DebugUndefined>`_
comment:3 by , 13 years ago
Milestone: | → 0.2.1 |
---|---|
Owner: | set to |
Status: | New → In Progress |
Okay, I have enabled this. And fixed two breaking places (simple). I leave this bug open for the next 14 days, if this all turns out to be a bad idea. Let's see! Commit: f1cdd278e7cf195e485567ed0d0d8a90cad81e48 and following
comment:4 by , 13 years ago
Status: | In Progress → Closed |
---|
13 days over, okay. We had a small bit of pain here and there, but it generally was acceptable.
comment:6 by , 13 years ago
Type: | defect → enhancement |
---|
Note:
See TracTickets
for help on using tickets.