ContentFile to string

1934 단어 djangoTILTIL

https://docs.djangoproject.com/en/4.0/ref/files/file/

print(name)
Raw content

print(type(name))
<class 'django.core.files.base.ContentFile'>

print(name.name)
ea59c949-5e4c-495d-a58d-93f5a0d31881.jpg

print(type(name.name))
<class 'str'>

base64 type url 을 변수에 담아 print 했을 때 Raw content 라고 찍혀서 내용이 변한 줄 알았다.
그래서 ContentFile Class 를 override 해 Raw content 로 return 하는 부분을 주석 처리했다.

알고보니 Raw content 라고 찍혀도 내용은 변하지 않는다.
공식 문서를 참고해서 string type 으로 변환했다.

좋은 웹페이지 즐겨찾기