문제

나는 반환하는 django보기가있다 HttpResponse 사용자의 브라우저를 브라우저에서 보는 대신 "다운로드"로 만드는 특수 마임 유형의 경우. 문제는 응답이 저장 될 기본 파일 이름이 사용자가 액세스하려고 시도한 URL과 마찬가지로 저장된다는 것입니다.

기본 파일 이름을 HttpResponse 객체 또는 이런 일을하기 위해 다른 URL로 리디렉션해야합니까?

도움이 되었습니까?

해결책

관련 예가 있습니다 문서:

from django.http import HttpResponse

def some_view(request):
    # Create the HttpResponse object with the appropriate headers.
    response = HttpResponse(mimetype='application/pdf', <snip>)
    response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
    return response
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top