后台使用python WEUI文件上传详解

1、首先看下前端界面:


2、前端代码:

Title


   


   

图片上传(最多三张):

url


3、view:

def test(request):

return render(request,'test.html')

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def upload_file(request):

# file_obj = request.FILES.get('file')

# files = request.FILES.getlist('file_field')

# print(files)

# print(file_obj)

# print(BASE_DIR)

    MEDIA_ROOT = os.path.join(BASE_DIR,"static/images/")

for file_objin request.FILES.getlist("file[]"):

file_path =MEDIA_ROOT+file_obj.name

print(file_path)

with open(file_path,'wb')as f:

for chunkin file_obj.chunks():

f.write(chunk)

return HttpResponse(file_path)

# files = request.FILES["file[]"]

# print(request.FILES.getlist("file[]"))

# print(type(files))

# print(files)

# print(len(request.FILES.getlist("file[]")))

# return HttpResponse('ok')

你可能感兴趣的:(后台使用python WEUI文件上传详解)