dynamically creating html code with python...

Diez B. Roggisch deets at nospam.web.de
Mon Aug 11 14:21:29 EDT 2008


anartz at anartz.cjb.net wrote:

> Hi,
> 
> Thanks for your patience.
> 
> I got the text displayed in the web browser with the following code:
> 
> [CODE]
> f=StringIO.StringIO()
> f.write('<html><head><title>data analysis site</title></head><body>')
> f.write("<p>This is a trial test</p>")
> f.write("</body></html>")
> 
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
> 
> Now I am trying to put both the image and the text together, but the
> following lines do not create the text with the chart that I expected.
> 
> [CODE]
> f=StringIO.StringIO()
> f.write('<html><head><title>data analysis site</title></head><body>')
> f.write("<p>This is a trial test</p>")
>
f.write(urllib.urlopen("http://localhost/myLibs/ChartLib.py",urllib.urlencode(TheData)))
> f.write("</body></html>")
> 
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
> 
> I am wondering if urllib.urlopen is the command I need to revise.
> 
> Thanks for the pointers as well. I will look into them.

That's bogus. instead of the urllib-stuff, you need to write out a <img>-tag
with the src pointing to your image - most probably like this:

<img src="/myLibs/ChartLib.py"/>

Diez



More information about the Python-list mailing list