Python-django-文件上传

 

1,后台

  

def upload(request):
    image = request.FILES.get('image')
    print(image.name)
    print(image.size)
    file = open(image.name, 'wb')
    for data in image.chunks(chunk_size=1024):
        file.write(data)
    return HttpResponse('successful')

 

 

2. 前端

<form action="" method="post" enctype="multipart/form-data">
        {% csrf_token%}
        <input type="file" name="image">
        <button type="submit">submit</button>
</form>

 

posted @ 2021-02-07 16:50  leungqingyun  阅读(53)  评论(0编辑  收藏  举报