Python 从响应中获取所选路径
我正在使用Python 从响应中获取所选路径,python,Python,我正在使用 response.headers['Content-Type'] = gluon.contenttype.contenttype('.xls') response.headers['Content-disposition'] = 'attachment; filename=projects.xls' 生成“另存为”对话框 有没有办法让用户获取所选路径?浏览器会向用户显示“另存为”对话框,然后将内容写入该文件。它不会通知服务器内容保存到哪个路径。恐怕您无法获得该信息。如果您的问题是如
response.headers['Content-Type'] = gluon.contenttype.contenttype('.xls')
response.headers['Content-disposition'] = 'attachment; filename=projects.xls'
生成“另存为”对话框
有没有办法让用户获取所选路径?浏览器会向用户显示“另存为”对话框,然后将内容写入该文件。它不会通知服务器内容保存到哪个路径。恐怕您无法获得该信息。如果您的问题是如何将文件内容发送给用户,您只需将内容写入响应对象即可。浏览器负责将文件实际写入用户选择的路径 在Django中,您可以执行以下操作:
def view(request):
# get the file content from somewhere
response = HttpResponse(file_content, mimetype='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=projects.xls'
return response
然后,浏览器将提示用户输入路径,并将文件“projects.xls”保存到该路径。如何将内容传递到文件projects.xls