Design problem, call function from HTML?

B

bart

This is the python way i have.

imgref = 'image.py'
out.write('<img src="%s">'
% (imgref)


in ASP.NET u can do something like this

<img src="<%# image() %>">

//allready loaded data
data

image(){
return data.img
}

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.
 
D

deelan

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/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top