python- 初步认识 上传文件

pip install -i https://pypi.douban.com/simple openpyxl

上面是导入表格的插件

 

1. 静态文件

 

 <div class="form-group">
                  <label for="exampleInputFile">上传文件</label>
                  <input type="file" name="file">
</div>

 

2.  views.py

 

from django.shortcuts import render,HttpResponse


def upload_list(request):

    if request.method == 'GET':

        return render(request, 'upload_list.html')

    #获取文件
    file_obj = request.FILES.get('file')

   
  # 写入文件
    f = open(file_obj.name, mode='wb')

    for chunk in file_obj.chunks():

        f.write(chunk)

    f.close()

    return HttpResponse('111')

 

posted @ 2022-04-17 19:49  我在春天等伱  阅读(50)  评论(0)    收藏  举报