在 GAE 中,文件'download'不断下载,而不是将内容写入 HTML



我正在学习在GAE中使用cookie。每次,我打开localhost:8080,一个名为"download"的文件,没有任何扩展名下载。当我在记事本中打开它时,它会显示"你已经在这里0次了"。因此,它没有将内容写入HTML,而是下载了一个包含内容的文件。

import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'type/plain'
visits  = self.request.cookies.get('visits', 0)
self.response.out.write("You've been here %s times." % visits)

app = webapp2.WSGIApplication([('/', MainPage),], debug = True)     

有人能告诉我为什么会发生这种事吗?我该如何避免?

正确的"内容类型"是"text/plain"。

self.response.headers['Content-Type'] = 'text/plain'

最新更新