[python-win32] ASP/Python problems with HTMLgen...

Andrew Bennetts andrew-pywin32 at puzzling.org
Tue Sep 2 11:41:07 EDT 2003


On Mon, Sep 01, 2003 at 08:14:52AM -0600, Brian Jarrett wrote:
> I've tried several ways of getting HTML generated using HTMLgen.  Here is the code I ended with:
> 
> <%@ Language = Python %>
> <%
> from HTMLgen import *
> 
> doc = SimpleDocument(title="Hello")
> doc.append(Heading(1, "Hello World"))
> doc.write()
> 
> %>
> 
> All it gives me is "<html><body></body></html>" when I view the source.
> Only Response.Write seems to work, but using it with the "doc" object above gives me a com error.
> 
> Can someone point me in the right direction?  Am I going to have to scrap using HTMLgen?

I'm guessing that 'doc.write()' writes to stdout, which is useless in an ASP
script.  You'll need to get the string that doc.write generates somehow, and
call Response.Write with it.

Something like this might work:

<%@ Language = Python %>
<%
from HTMLgen import *
from cStringIO import StringIO

doc = SimpleDocument(title="Hello")
doc.append(Heading(1, "Hello World"))
f = StringIO()
doc.write(f)
Response.Write(f.getvalue())

%>

-Andrew.




More information about the Python-win32 mailing list