我有一个输出pdf的Django视图,如下所示:
def evaluation_download(request):
....
response = HttpResponse()
response["mimetype"] = "application/force-download"
response['Content-Disposition'] = 'attachment; filename="evaluation.pdf"'
c = canvas.Canvas(response)
.... # Draw stuff on canvas
c.showPage()
c.save()
return response这段代码正确地生成了PDF文件,但下载的文件名为evaluation.pdf.html。为什么?
发布于 2015-07-23 14:56:55
您忘记设置适当的content_type
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="evaluation.pdf"'有关更多信息,请阅读the docs。
https://stackoverflow.com/questions/31580139
复制相似问题