views:

37

answers:

1

I'm writing an app that pulls chunks of svg together and serves them as part of a page mixed with css and javascript. I'm using Python and Google App Engine. What I'm doing works fine on my local development server but fails to render once it's deployed.

So here's some test python to build a response:

self.response.headers.add_header('Content-Type','application/xhtml+xml')
self.response.out.write("<html xmlns='http://www.w3.org/1999/xhtml'&gt;")
self.response.out.write("<body>")
self.response.out.write("<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'&gt;")
self.response.out.write("<rect x='10' y='10' height='100' width='100' />")
self.response.out.write("</svg>")
self.response.out.write("</body></html>")

Now if I request this on the local development server (I'm using Safari, but Firefox works too) it works and I see a black square. If I create an xhtml document with this markup, and I upload that page to a server, I will see the square, but when I deploy this app on a server and run it, I don't see the square. All the markup is there when I look at View Source, but it wont render.

I've tried using different mime types. I've tried adding: <!DOCTYPE html> or adding <?xml version=1.0"?> and none of it makes a difference.

Any ideas?

+1  A: 

I solved the problem. This line:

self.response.headers.add_header('Content-Type','application/xhtml+xml')

was not working. I determined that by using http://web-sniffer.net to see what content-type accompanied the page, and it was always returning the default text/html.

The correct syntax is:

self.response.headers["Content-Type"] = "application/xhtml+xml"

Now everything works just peachy.

Not many questions on svg + google-app-engine on SO, but this might be useful for someone else in the future.

Silromen