쟝고 한글 파일 다운로드 문제

조회수 1029회
post = get_object_or_404(Post_Notice, id = id)
filename = post.file_attached.name.split('/')[-1] 
response = HttpResponse(post.file_attached, content_type = 'application/force-download')    
response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)   
return response

django에서 위와같이 view 함수를 만들어

HttpResponse를 return 하면

파일이름이 영어일때는 괜찮은데,

한글 또는 특수문자가 들어있을 경우

아예 다운로드 파일이름이 잘못되거나 없어집니다.

어떻게 해야하나요,,ㅠㅠㅠㅠㅠ

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • filename에 한글 또는 특수문자가 문제가 된다면 urlencode를 이용해서 변환한다음 사용해보시기 바랍니다.

    참고: urllib.parse

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)