通过链接提供pdf文件,下载为pdf.htm格式

2024-06-09 19:04:52 发布

您现在位置:Python中文网/ 问答频道 /正文

板条箱功能允许用户通过链接下载pdf文件。工作正常,用户保存的唯一问题是.html。所以所有的文件都是文件.pdf.html. 你知道吗

def download(request,ticket_id):
    ticket_path = str(Ticket.objects.get(id=ticket_id).upload)
    with open('files/media/' + ticket_path, 'rb') as pdf:
        response = HttpResponse(pdf.read())
        response['content_type'] = 'application/pdf'
        response['Content-Disposition'] = 'attachment;filename="file.pdf"'
        return response

为什么?你知道吗


Tags: 文件path用户功能idpdf链接response