我正在学习在GAE中使用cookies。每次,我打开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)
可以请任何人告诉我为什么会这样,我该如何避免呢?
答案 0 :(得分:0)
正确的'Content-Type'是'text / plain'。
self.response.headers['Content-Type'] = 'text/plain'