쟝고 한글 파일 다운로드 문제
조회수 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
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력