枫叶资源网–官网地址
星际导航–官网地址
观看新剧点播–官网地址
后端接收数据的代码
def ajax_upload(request):
"""
接收前端 Ajax 发送过来的数据和文件
:param request:
:return:
"""
import os,json
response = BaseReponse()
try:
print('reqpost数据>>:', request.POST)
print('reqfile数据>>:', request.FILES)
file_obj = request.FILES.get('sub_file_name')
print('接收到的文件>>:', file_obj)
print('参数key one 的值>>:', request.POST.get('one'))
print('参数key two 的值>>:', request.POST.get('two'))
# file_dir = os.path.join(settings.BASE_DIR, 'img') # 设置接收文件的绝对路径
# print("文件保存的绝对路径>>:", file_dir)
"""下面的是把接收到的文件保存到服务器上"""
file_path = os.path.join('static', file_obj.name) # 组合文件的完整路径
new_file_obj = open(file_path, 'wb')
[new_file_obj.write(chunk) for chunk in file_obj.chunks()]
new_file_obj.close()
"""设置一下返回信息和状态"""
response.status = True
response.data = file_path
except Exception as e:
response.status = False
response.error = "上传失败"
return HttpResponse(json.dumps(response.__dict__))
5207

被折叠的 条评论
为什么被折叠?



