On 08/20/2012 02:17 PM, Yarin wrote:

|
defindex():

globalmy_var
 my_var ="something"
 content ='''<html><body><h1>My Page</h1><p>
 {{=my_var}}
 {{=request.raw_args}}
 </body></html>'''

 output =render(content,context=dict(n=5))
returnoutput
|

but this won't work- it gives an error:

    <type 'exceptions.NameError'> name 'my_var' is not defined


Questions:

  * How do I create variables in the controller that can then be
    referenced in the rendered view?
  * Can I access global vars like request/response in the rendered view?
  * what does the context dictionary do?

(I tried but couldn't make sense of the render function in template.py. I'm clueless to the scoping consequences of this stuff...)




I'm still pretty new to web2py, but my experience so far is that anything in the view has to be in the context dictionary. Perhaps change the context=dict() to this (untested)?

|output =render(content,context=dict(n=5, my_var=my_var))
|

--



Reply via email to