How to generate xhtml code with Resource.render?
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
On Fri, Aug 27, 2004, Krzystof Nowak wrote:
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?
You might want to look at http://twistedmatrix.com/documents/current/howto/using-twistedweb#auto17 for this. In particular:
class Resource(resource.Resource): def render(self, request):
I believe you want to be doing this by returning a string from render_GET, rather than by reimplementing render. -Mary
On Fri, 27 Aug 2004, Mary Gardiner wrote:
class Resource(resource.Resource): def render(self, request):
I believe you want to be doing this by returning a string from render_GET, rather than by reimplementing render.
-Mary
Unfortunately it makes no difference :( Browser still doesnt understand <svg:*> correctly although both codes received by browser are the same. Anyway, thanks Krzys
On Fri, 27 Aug 2004 16:39:53 +0200 (MEST), Krzystof Nowak <knowak@mail.desy.de> wrote:
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?
I'll guess mime-type. You might have to set it to something other than the default, text/html. Dunno what to, though. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com
For xhtml, you need to find out whether the client will accept application/xml+xhtml. If it will, then change the MIME type to that: request.setHeader('Content-type', 'application/xml+xhtml') Otherwise, make sure it's text/html. You may need to do this by force, if the file extension isn't '.htm' or '.html'. Dominic On Fri, 27 Aug 2004 11:38:55 -0400, Christopher Armstrong <radeex@gmail.com> wrote:
On Fri, 27 Aug 2004 16:39:53 +0200 (MEST), Krzystof Nowak <knowak@mail.desy.de> wrote:
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?
I'll guess mime-type. You might have to set it to something other than the default, text/html. Dunno what to, though.
-- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-- // Dream in black and white - // model cities, shooting up in the air
Thanks alot. Now its working :) Krzys On Fri, 27 Aug 2004, Dominic Fox wrote:
For xhtml, you need to find out whether the client will accept application/xml+xhtml. If it will, then change the MIME type to that:
request.setHeader('Content-type', 'application/xml+xhtml')
Otherwise, make sure it's text/html. You may need to do this by force, if the file extension isn't '.htm' or '.html'.
Dominic
On Fri, 27 Aug 2004 11:38:55 -0400, Christopher Armstrong <radeex@gmail.com> wrote:
On Fri, 27 Aug 2004 16:39:53 +0200 (MEST), Krzystof Nowak <knowak@mail.desy.de> wrote:
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?
I'll guess mime-type. You might have to set it to something other than the default, text/html. Dunno what to, though.
-- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-- // Dream in black and white - // model cities, shooting up in the air
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Do you know why now JavaScript doesnt work on my page? It is working when the page is text/html. Sorry for maybe stupid questions... but I cant manage it alone :/ Krzys
OK, Im sorry, it was of course silly question. I have surrounded Jscript with <![CDATA[..]]> but it should be //<[!CDATA[...//]]>. Sorry for disturbing you. This question had nothing to twisted.web topic. Krzys On Mon, 30 Aug 2004, Krzystof Nowak wrote:
Do you know why now JavaScript doesnt work on my page? It is working when the page is text/html. Sorry for maybe stupid questions... but I cant manage it alone :/
Krzys
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (5)
-
Christopher Armstrong
-
Dominic Fox
-
Krzystof Nowak
-
Krzysztof Nowak
-
Mary Gardiner