【问题标题】:In GAE, file 'download' keeps downloading instead of writing content to HTML在 GAE 中,文件“下载”不断下载而不是将内容写入 HTML
【发布时间】:2017-08-29 16:59:18
【问题描述】:

我正在学习在 GAE 中使用 cookie。每次,我打开 localhost:8080,一个名为“下载”的文件,没有任何扩展下载。当我在记事本中打开它时,它有“你来过这里 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)     

谁能告诉我为什么会发生这种情况,我该如何避免?

【问题讨论】:

    标签: python google-app-engine webapp2


    【解决方案1】:

    正确的“Content-Type”是“text/plain”。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2022-10-13
      • 2021-12-20
      • 1970-01-01
      • 2012-01-07
      相关资源
      最近更新 更多