Skip to content

Commit 7c5a00b

Browse files
committed
File Binary View
1 parent 141518c commit 7c5a00b

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed
86 Bytes
Binary file not shown.
Binary file not shown.

request_response_mastering/myapp/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
path("FormData/", views.FormData),
1111
path("RequestBody/", views.RequestBody),
1212
path("FileDownload/", views.FileDownload),
13+
path('FileBinaryView/', views.FileBinaryView),
1314
]

request_response_mastering/myapp/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,13 @@ def FileDownload(request):
8686
response = HttpResponse(myfile.read(),content_type="application/octet-stream")
8787
response['Content-Disposition'] = f'attachment; filename="{file_name}"'
8888
return response
89+
90+
def FileBinaryView(request):
91+
file_path = os.path.join(settings.BASE_DIR,"file.pdf")
92+
93+
file_name = os.path.basename(file_path)
94+
95+
with open(file_path, 'rb') as myfile:
96+
response = HttpResponse(myfile.read(),content_type="application/pdf")
97+
response['Content-Disposition'] = 'inline'
98+
return response

0 commit comments

Comments
 (0)