BaseHTTPRequestHandler reading .html with python code
aspineux
aspineux at gmail.com
Fri Apr 6 13:44:15 EDT 2007
On 6 avr, 11:52, gcmart... at gmail.com wrote:
> H!
>
> I was wondering how I can do something like this.
Use a template engine like :
Genshi
Django/Jinja
Cheetah
Kid template
For more engine look at
http://www.turbogears.org/cogbin/
And maybe what you are looking fore is a complete framework like :
turbogears
pylon
django
Hope this help
>
> file.html
> ---------
> <b>hello world</b>
> <special pythoncodetag>
> print 'hello world'
> #or display str(time.localtime()[7])
> </special pythoncodetag>
>
> webserver.py
> ---------
> def do_GET(self):
> try:
> if self.path.endswith(".html"):
> f = open(curdir + sep + self.path) #self.path has /
> test.html
> self.send_response(200)
> self.send_header('Content-type', 'text/html')
> self.end_headers()
> # now display the <b>hello world</b> and run the python code.
> self.wfile.write(f.read())
> f.close()
> return
>
> I saw the mod python for apache and some PSP but I really want to know
> how they do this.
> Is there are special module for doing this ?
>
> Or is there something like this:
> ---------------------------
> 1. a running python program
> 2. include with write(f.read()) a extra python code inside the already
> running python program.
>
> How they handle this ?
More information about the Python-list
mailing list