We know locals() fits well in this situation.
But I am working in a system develop returning locals() from all
controllers. It's a pain to discover where things are defined and if a
change in a controller (ie. killing some "unused" variables) will or not
affect that view. Mainly the bigger ones.
It's good to be explicit whenever possible.
So, I wouldn't lay on returning locals() everywhere. I'd rather
return(dict1=dict1, dict2=dict2, ...) in this simple situation with few
variables.
--
Vinicius Assef
On 07/17/2012 06:50 PM, adohertyd wrote:
Simple as that :) thanks Massimo Web2py is fantastic
On Tuesday, 17 July 2012 22:45:48 UTC+1, Massimo Di Pierro wrote:
replace
return dict(ReturnedDict=OtherDict)
with
return locals()
On Tuesday, 17 July 2012 16:40:00 UTC-5, adohertyd wrote:
In my function page2(): I return a dictionary to be accessed by
the page2 HTML view. In the page2 function I have some other
dictionaries. What I want to do to be able to use the
non-returned dictionaries in the HTML code to show some items.
This is a sample of what I want: Hope it's clear
|
defpage2():
Dict1={key1:{keyA:value,keyB:value,keyC:value}
Dict2={key2:{keyD:value,keyE:value,keyF:value}
OtherDict={key:value,key:value...}
returndict(ReturnedDict=OtherDict)
|
|
page2.html:
<ul>
{{forx inReturnedDict:}}
{{ifx inDict1:}}
<li>{{=Dict1[x]['keyA']}}{{=Dict1[x]['keyB']</li>
{{elifx inDict2:}}
<li>{{=Dict2[x]['keyD']}}{{=Dict2[x]['keyE']</li>
{{pass}}
</ul>
|
--
--