Download 强制下载生成的文件

Download 强制下载生成的文件,download,pyramid,Download,Pyramid,我需要从金字塔应用程序导出GPX文件。我已经在jinja2中准备了gpx模板,它运行良好,但现在,我想提供给用户下载,而不是在浏览器中显示文件。 怎么做?我找到了解决方案: response = render_to_response( <template>, <data>, request=request) response.content_type = 'application/gpx+xml' response.content_disposition = 'attac

我需要从金字塔应用程序导出GPX文件。我已经在jinja2中准备了gpx模板,它运行良好,但现在,我想提供给用户下载,而不是在浏览器中显示文件。 怎么做?

我找到了解决方案:

response = render_to_response( <template>, <data>, request=request)
response.content_type = 'application/gpx+xml'
response.content_disposition = 'attachment; filename="file.gpx"'
return response
response=render\u to\u response(,request=request)
response.content_type='application/gpx+xml'
response.content_disposition='附件;filename=“file.gpx”'
返回响应