我有一个 Django 视图,它返回一个HttpResponse
使用特殊的 MIME 类型使用户的浏览器“下载”文件而不是在浏览器中查看它。问题在于,保存响应的默认文件名是用户尝试访问的 URL。
有没有办法在文件中包含默认文件名HttpResponse
对象还是我必须重定向到不同的 URL 才能实现此目的?
中有一个相关的例子docs http://docs.djangoproject.com/en/dev/howto/outputting-pdf/:
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
return response
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)