Render._add_global does not work. #217

Open
vwochnik opened this Issue Mar 22, 2013 · 5 comments

Projects

None yet

2 participants

@vwochnik

Hello guys. The add_global method in Render is completely useless, because it gets supressed by __getattr_ which will raise an AttributeError due to non-existent template "_add_global".

Does not work:

render._add_global('bar', 'foo')

Instead, I have to manually

render._keywords['global']['foo'] = 'bar''

This is undesired behavior, I gess. Also, the function is unused in the template module itself, so I assume it was made for exactly this purpose.

@gardiner

__getattr__ gets only called for missing attributes. For me _add_global works exactly as it's supposed to.

@vwochnik
@gardiner

Hmm. I've just tested (again) with web.py 0.36 and 0.37 and everything works as expected. Which version are you using?

>>> import web
>>> r = web.template.render('.')
>>> r._add_global('value', 'key')
>>> print web.__version__
0.36


>>> import web
>>> print web.__version__
0.37
>>> r = web.template.render('.')
>>> r._add_global('value', 'key')
>>>
@vwochnik
@gardiner

Yes, version 0.34 did not have a method _add_global. If I'm not mistaken you can add globals in 0.34 with a globals keyword argument:

>>> import web
>>> print web.__version__
0.34
>>> r = web.template.render('.', globals={'key':'value'})
>>> r.test() #test.html contains the line "Hello $key."
<TemplateResult: {'__body__': u'Hello value.\n'}>
>>>

(The render constructor passes additional keyword arguments down to the template constructor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment