2017-05-09 4 views
0

ユーザーがリンク別にPDFファイルをダウンロードできるようにする機能。うまく動作します。唯一の問題は、ユーザーが保存するものが.htmlです。したがって、すべてのファイルはfile.pdf.htmlです。リンク別PDFファイルの提供、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 

なぜですか?

答えて

0

あなたはHttpResponse(pdf.read(), content_type='application/pdf')content_typeを移動する必要があり、それはのHttpResponse

+0

小さなタイプミスのattributeです。代わりにread()の準備ができました –

+0

気づいてくれてありがとう、固定! –

関連する問題