flask-genshi
flask-genshi copied to clipboard
Allow configuration of genshi variable lookup mechanism
Genshi allows different behaviors when looking up variables in a template. By default this is 'strict' meaning an undefined variable will trigger an exception when rendering the template.
They also have an optional 'lenient' mechanism which results in an empty string or false value when such a variable is found. This setting is sometimes more appropriate in production.
To configure this you can pass a variable_lookup=xxx to the template loader where xxx is either a string or a class.
Currently I use the following code to set it:
genshi = Genshi(app)
genshi.template_loader.variable_lookup = 'lenient'
It would be nicer if i could configure it using a config variable app.config['GENSHI_VARIABLE_LOOKUP'] for example.
I didn't find any other config key in the current code, so i'm not sure if it's an acceptable approach ?
It feels dirty, but I suppose you have a point about production where fault-tolerance might have a higher priority than correctness. In the rewrite branch this would be easy to add yourself via subclassing, but maybe there should be a config option. I'll have to think on it and discuss with Armin.