2017-08-29 68 views
0

我正在学习在GAE中使用Cookie。每次我打开localhost:8080,一个名为“下载”的文件,没有任何扩展下载。当我用记事本打开它时,它有“你已经来过0次了。”因此,不用将内容写入HTML,而是使用内容下载文件。在GAE中,文件'下载'不断下载,而不是将内容写入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

正确的'Content-Type'是'text/plain'。

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

是的,已经修好了。愚蠢的错误。抱歉。 –