金字塔力下载生成的文件

问题描述

我需要从金字塔应用程序导出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