Design problem, call function from HTML?

Discussion in 'Python' started by bart, May 30, 2005.

  1. bart

    bart Guest

    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.
     
    bart, May 30, 2005
    #1
    1. Advertising

  2. bart

    deelan Guest

    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/> .
     
    deelan, May 30, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. grbgooglefan
    Replies:
    2
    Views:
    429
    Pascal Bourguignon
    Jan 30, 2008
  2. grbgooglefan
    Replies:
    4
    Views:
    446
    Kenny McCormack
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    0
    Views:
    397
    grbgooglefan
    Jan 30, 2008
  4. Alok
    Replies:
    3
    Views:
    253
  5. THAKUR PRASHANT SINGH

    Class Function call vs Normal Function call

    THAKUR PRASHANT SINGH, Feb 26, 2010, in forum: Ruby
    Replies:
    7
    Views:
    193
    THAKUR PRASHANT SINGH
    Feb 27, 2010
Loading...

Share This Page