[Twisted-web] How to generate xhtml code with Resource.render?

Krzystof Nowak knowak at mail.desy.de
Fri Aug 27 08:39:53 MDT 2004


I have written a python's rpy script which generats a web page. All seems
works fine, but for now I was playing with html. Now, I decided to
upgrade
to xhtml (I need a different namespaces, you will see below). I've have
written an xhtml file:
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg">
<head></head><body>

List
<ul>
 <li>one</li>
 <li>two</li>
</ul>

<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="10cm"
height="10cm">
<svg:title> A two shapes</svg:title>
<svg:g transform="scale(0.5)">
<svg:polygon style="fill:red; stroke:blue; stroke-width:10" points="350,
75 379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161
321,161"/>
</svg:g>
</svg:svg>

</body></html>

And it is working. But when I'm trying to generate this file by rpy
script in this way:

class Resource(resource.Resource):
	def render(self, request):
		request.write('''
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
<head></head><body>

List
<ul>
 <li>one</li>
 <li>two</li>
 <li>three</li>
</ul>

<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="10cm" height="10cm">
<svg:title> A two shapes</svg:title>
<svg:g transform="scale(0.5)">
<svg:polygon style="fill:red; stroke:blue; stroke-width:10" points="350,75 379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161"/>
</svg:g>
</svg:svg>

</body></html>
''')
		request.finish()
		return server.NOT_DONE_YET
resource = Resource()

browser dosent seem to understand that its xhtml code. I think I'm missing
something very easy, maybe I'm not properly understand philosophy of xhtml
or python.web. Do you know how to manage with this problem?

(Sorry for my english :) )

Cheers
Krzys



More information about the Twisted-web mailing list