gpt4 book ai didi

python - 如何将 Google App Engine 中的 python 脚本中的字符串作为文件发送到浏览器客户端

转载 作者:行者123 更新时间:2023-11-30 23:59:48 26 4
gpt4 key购买 nike

我有一个在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com