flask-genshi icon indicating copy to clipboard operation
flask-genshi copied to clipboard

Allow configuration of genshi variable lookup mechanism

Open rslinckx opened this issue 13 years ago • 1 comments

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 ?

rslinckx avatar Oct 27 '11 09:10 rslinckx

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.

dag avatar Oct 27 '11 14:10 dag