embedding python in HTML
Georg Brandl
g.brandl-nospam at gmx.net
Fri Feb 17 10:00:25 EST 2006
John Salerno wrote:
> Kirk McDonald wrote:
>
>> A more common (and bare-metal) approach is CGI. In CGI, a request for a
>> page runs a script, the output of which is the HTML page. I think this
>> only requires that the server has Python installed, which you have said
>> is the case. Python has signifigant standard library support for writing
>> CGI.
>
> Thanks, that makes much more sense to me now. But does this mean I can
> still write HTML normally? What would an example be of having HTML
> within a Python script? I have a hard time picturing this, because I
> imagine that most of my pages will be almost all HTML, with just a bit
> of Python here and there, perhaps to insert headers and footers. Is all
> the HTML just wrapped in a big print statement, or something like that?
When writing for CGI, it will be.
It will basically look like this:
#!/bin/env python
# these are custom headers, Content-type is mandatory
print "Content-Type: text/html"
# an empty line separates headers from content
print
print "<html>..."
# do stuff here
print "...</html>"
Georg
More information about the Python-list
mailing list