我有一个在 Google App Engine 内运行的 Python Web 应用程序。
应用程序根据用户需求创建一个字符串,我希望该字符串作为文件发送到浏览器客户端(应用程序/八位字节流?)。
我怎样才能实现这一点?
最佳答案
如果您使用的是 App Engine 自己的,简单 webapp框架,最简单的方法是使用请求处理程序对象的 get
方法,如下所示:
def get(self):
thestring = 'helloworld' # or however else it's synthesized;-)
self.response.headers.add_header(
'content-disposition', 'attachment', filename='hw.txt')
self.response.out.write(thestring)
当然,如果您有其他不同的目标,您可以使用更复杂的方法,但这符合您所述的目标。
关于python - 如何将 Google App Engine 中的 python 脚本中的字符串作为文件发送到浏览器客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2089635/