简体   繁体   English

在GAE中,文件“下载”保持下载状态,而不是将内容写入HTML

[英]In GAE, file 'download' keeps downloading instead of writing content to HTML

I'm learning to use cookies in GAE. 我正在学习在GAE中使用Cookie。 Every time, I open localhost:8080, a file named just 'download' without any extension downloads. 每次,我打开localhost:8080,一个名为“ download”的文件,没有任何扩展名下载。 When I open it in notepad, it has "You've been here 0 times." 当我在记事本中打开它时,它显示“您去过这里0次”。 So, instead of writing the content to HTML it downloads a file with the content. 因此,与其将内容写入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)     

Can please anyone tell me why this is happening and how can I avoid it? 能否请任何人告诉我为什么会这样以及如何避免呢?

正确的“内容类型”是“文本/纯文本”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复HTML下载而不是图像文件 - How to fix HTML downloading instead of image file python脚本,下载html内容而不是流视频 - python script, downloading html content instead of streaming video 发送Excel文件以下载GAE python - Send excel file for downloading GAE python 为什么 Python 模块请求下载 HTML 页面而不是文件? - Why is the Python module requests downloading the HTML page instead of a file? 下载 URL 到文件...不返回 JSON 数据,而是登录 HTML - Downloading URL To file... Not returning JSON data but Login HTML instead 使用 html.A 破折号下载文件,但文件显示 html - dash download file using html.A, but file shows html instead 从 PHP 或 Python 中的 FTP 服务器读取或下载文件的 5kb,而不是下载或读取整个文件 - Read or download 5kb of a file from FTP server in PHP or Python instead of downloading or reading whole file 使用 requests.get 下载 rar 文件并将内容写入 python 上的文件问题 - Downloading a rar file with requests.get and writing the content into a file issue on python 创建的下载链接打开链接而不是下载它 - the created download link to open the link instead of downloading it 如何将文件从一个字节下载到另一个字节(例如,下载html文件的页脚) - How to download a file from one byte to another byte.(for example downloading footer of an html file)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM