我有一个Django视图,输出这样的pdf:
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
。为什么呢?
答案 0 :(得分:4)
您忘了设置合适的content_type
:
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="evaluation.pdf"'
阅读the docs了解详情。