質問編集履歴

1

修正

2020/01/13 09:52

投稿

django
django

スコア19

test CHANGED
File without changes
test CHANGED
@@ -42,11 +42,23 @@
42
42
 
43
43
  )
44
44
 
45
- if not file_name:
45
+ try:
46
46
 
47
- return HttpResponse()
47
+ with open(file_name, "rb") as f:
48
48
 
49
+ a = f.read()
50
+
49
- return HttpResponse(File(codecs.open(file_name, 'r', 'utf-8', 'ignore')), content_type="image/jpeg")
51
+ return HttpResponse(a, content_type="image/jpeg")
52
+
53
+ except IOError:
54
+
55
+ red = Image.new('RGBA', (1, 1), (255, 0, 0, 0))
56
+
57
+ response = HttpResponse(content_type="image/jpeg")
58
+
59
+ red.save(response, "JPEG")
60
+
61
+ return response
50
62
 
51
63
 
52
64
 
@@ -65,3 +77,15 @@
65
77
 
66
78
 
67
79
  ```
80
+
81
+
82
+
83
+
84
+
85
+ 上記のコードだと下のエラーが発生します。
86
+
87
+ ```
88
+
89
+ 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
90
+
91
+ ```