Google App Engine中的Python脚本提供的内联SVG未显示

时间:2010-10-01 14:35:14

标签: python google-app-engine xhtml svg

我正在编写一个应用程序,将svg块整合在一起,并将它们作为混合了css和javascript的页面的一部分提供。我正在使用Python和Google App Engine。我正在做的工作在我的本地开发服务器上正常工作,但一旦部署就无法渲染。

所以这里有一些测试python来构建响应:

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

现在,如果我在本地开发服务器上请求这个(我使用的是Safari,但Firefox也可以),它可以工作,我看到一个黑色方块。如果我使用此标记创建一个xhtml文档,并将该页面上传到服务器,我将看到该正方形,但是当我在服务器上部署此应用程序并运行它时,我看不到该正方形。当我查看View Source时,所有标记都在那里,但它不会渲染。

我尝试过使用不同的mime类型。 我尝试添加:<!DOCTYPE html>或添加&lt; ?xml version=1.0"?>,但没有一个有所作为。

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

我解决了这个问题。 这一行:

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

无效。我确定通过使用http://web-sniffer.net查看页面附带的内容类型,并且始终返回默认文本/ html。

正确的语法是:

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

现在一切都很有效。

在SO上关于svg + google-app-engine的问题不多,但这可能会对其他人有用。