Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Render._add_global does not work. #217

Open
vwochnik opened this Issue · 5 comments

2 participants

vwochnik Ole Trenner
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.

Ole Trenner

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

vwochnik
Ole Trenner

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
Ole Trenner

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
Something went wrong with that request. Please try again.