2017-05-09 6 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

알아두면 고맙습니다. –