配置 MIME 类型

发布于 2024-10-30 20:54:35 字数 2185 浏览 4 评论 0原文

您好,我想配置我的 mime 类型:

KML 文件的 MIME 类型是

* application/vnd.google-earth.kml+xml

如何使用 google 应用引擎执行此操作?我在如下所示的模板上生成 KML:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>{% for article in articles %}{% if article.geopt %}
<Placemark><name></name>
<description>
<![CDATA[{% if article.kmluri2view %}<img src="http://{{host}}/images/{{ article.kmluri2view.key.id }}.jpg">{% endif %}<a href="http://{{host}}/{{article.key.id}}"> {{ article.title }} </a><br/>{{article.text}}]]></description><Point><coordinates>{{article.geopt.lon|floatformat:2}},{{article.geopt.lat|floatformat:2}}</coordinates></Point>
</Placemark>{% endif %}{% endfor %}
</Document>
</kml>

更新了代码 我尝试设置 MIME 类型,如下所示。我如何验证它是否有效?

class KMLHandler(webapp.RequestHandler):
     def get(self):            
        start=datetime.datetime.now()-timedelta(days=10)#vary  
        host = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])       
        logging.debug('host '+host)                
        count = int(self.request.get('count')) if not self.request.get('count')=='' else 1000

        from google.appengine.api import memcache
        memcache.flush_all()
        memcache_key = "ads"
        data = memcache.get(memcache_key)
        if data is None:
          a= Ad.all().filter("modified >", start).filter("url IN", ['www.koolbusiness.com']).filter("published =", True).order("-modified").fetch(count)
          memcache.set("ads", a)  
        else:
          a = data
        dispatch='templates/kml.html'
        template_values = {'a': a , 'request':self.request, 'host':host}
        path = os.path.join(os.path.dirname(__file__), dispatch)
        self.response.headers['Content-Type'] = 'application/vnd.google-earth.kml+xml'
        self.response.out.write(template.render(path, template_values))

Hi I want to configure my mime type:

The MIME type for KML files is

* application/vnd.google-earth.kml+xml

How can I do this with google app engine? I generate KML on a template that looks like this:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>{% for article in articles %}{% if article.geopt %}
<Placemark><name></name>
<description>
<![CDATA[{% if article.kmluri2view %}<img src="http://{{host}}/images/{{ article.kmluri2view.key.id }}.jpg">{% endif %}<a href="http://{{host}}/{{article.key.id}}"> {{ article.title }} </a><br/>{{article.text}}]]></description><Point><coordinates>{{article.geopt.lon|floatformat:2}},{{article.geopt.lat|floatformat:2}}</coordinates></Point>
</Placemark>{% endif %}{% endfor %}
</Document>
</kml>

Updated the code I try set the MIME type like below. How can I verify it works?

class KMLHandler(webapp.RequestHandler):
     def get(self):            
        start=datetime.datetime.now()-timedelta(days=10)#vary  
        host = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])       
        logging.debug('host '+host)                
        count = int(self.request.get('count')) if not self.request.get('count')=='' else 1000

        from google.appengine.api import memcache
        memcache.flush_all()
        memcache_key = "ads"
        data = memcache.get(memcache_key)
        if data is None:
          a= Ad.all().filter("modified >", start).filter("url IN", ['www.koolbusiness.com']).filter("published =", True).order("-modified").fetch(count)
          memcache.set("ads", a)  
        else:
          a = data
        dispatch='templates/kml.html'
        template_values = {'a': a , 'request':self.request, 'host':host}
        path = os.path.join(os.path.dirname(__file__), dispatch)
        self.response.headers['Content-Type'] = 'application/vnd.google-earth.kml+xml'
        self.response.out.write(template.render(path, template_values))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-11-06 20:54:35

只需将响应中的 Content-Type 标头设置为您想要的 mimetype 即可。例如,如果您使用的是 webapp,则可以这样做:

self.response.headers['Content-Type'] = 'application/vnd.google-earth.kml+xml'

Simply set the Content-Type header in the response to the mimetype you want. If you're using webapp, for instance, you do it like this:

self.response.headers['Content-Type'] = 'application/vnd.google-earth.kml+xml'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文