Design problem, call function from HTML?

deelan ggg at zzz.it
Mon May 30 05:52:47 EDT 2005


bart wrote:
(...)
> Is there any remote possibility u can pulloff the same in python? Now
> i have to process my data to display page and do it again to generate
> my image (execute same code twice).
> 
> One solution would be to save the image to harddisk and then load it.
> But rather keep it clean as return value.

something like Cheetah might help here:

 >>> from Cheetah.Template import Template
 >>> t = '<img src="$image">'

 >>> data = {}
 >>> data['img'] = 'foo.jpg'
 >>> def image(): return data['img']
...
 >>> T = Template(source=t, searchList=[{'image':image}])
 >>> T
<img src="foo.jpg">

...or you can access "img" directly in the template:

 >>> t = '<img src="$image.img">'
 >>> data = {}
 >>> data['img'] = 'foo.jpg'
 >>> T = Template(source=t, searchList=[{'image':data}])
 >>> T
<img src="foo.jpg">

say that "data" changes, you don't have to compile the template
again, just issue a render command again:

 >>> data['img'] = 'BAZ.jpg'
 >>> T
<img src="BAZ.jpg">


see:
<http://cheetahtemplate.org/>



-- 
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog <http://blog.deelan.com/> .



More information about the Python-list mailing list