注意:这是演示的代码,是把static的路径都加入到了settings.py文件中了
一、图片传输
# 图片传输
from django.http import FileResponse
def image(request):
if request.method == 'GET':
# 图片实际路径
img_file = os.path.join(BASE_DIR, r'static\weichat\img\1.png')
if not os.path.exists(img_file):
return HttpResponse(content='文件不存在! ', status=200)
else:
data = open(img_file, 'rb')
return FileResponse(data, content_type='image/png')
pass
二、视频传输
# 视频传输
from django.http import FileResponse
def video(request):
if request.method == 'GET':
# 视频实际路径
img_file = os.path.join(BASE_DIR, r'static\upfile\video\1.mp4')
if not os.path.exists(img_file):
return HttpResponse(content='文件不存在! ', status=200)
else:
data = open(img_file, 'rb')
return FileResponse(data, content_typ