Re: dynamically creating html code with python...
anartz at anartz.cjb.net
anartz at anartz.cjb.net
Mon Aug 11 11:30:06 EDT 2008
Sorry, my fault...
I am trying to build a web application for data analysis. Basically some data will be read from a database and passed to a python script (myLibs.py) to build an image as follows.
[CODE]
f=urllib.urlopen("http://localhost/path2Libs/myLibs.py",urllib.urlencode(TheData))
print "Content-type: image/png\n"
print f.read()
f.close()
[/CODE]
This section behaves as expected, and I can see the chart on the web-page.
Now, I would like to add some text and possibly more charts (generated in the same way) to my web-page. This is what I need help with.
I tried to add some html code to the f variable (file-type variable) before and after the plot generated (see first post). When I load the page in a browser, I get a blank page, not even the chart (that I used to get) appears any more.
There is no error messages in the server's error log, and when I run it as a python script I get the following output:
Content-type: image/png\n
My question:
How can I use python to dynamically add descriptive comments (text), and possibly more charts to the web-page?
Hope this is more explanatory.
Thanks
Anartz at anartz.cjb.net wrote :
> Hi,
>
> how can I combine some dynamically generated html code (using python) with the output of a urllib.openurl() call?
>
> I have tried to use the StringIO() class with .write functions, but it did not work. Below is the code that does not work.
>
> [CODE]
> f=StringIO.StringIO()
> f.write('<html><head><title>data analysis</title></head><body>')
> f.write(urllib.urlopen("http://localhost/path2Libs/myLibs.py", urllib.urlencode(TheData)))
> f.write("</body></html>")
>
> print "Content-type: text/html\n"
> print f.read()
> f.close()
> [/CODE]
>
> What is wrong with this approach/code? Is there an easier way of doing it?
>
> Thanks.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list