Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline SVG Served By Python Script in Google App Engine Not Appearing

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'>")
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'>")
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?

like image 941
Silromen Avatar asked Oct 01 '10 14:10

Silromen


Video Answer


1 Answers

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.

like image 113
Silromen Avatar answered Sep 23 '22 20:09

Silromen