1

day 76 滑动窗口 ,头像上传

一、上传文件

 

 前端html

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form action="/qigeming/" method="post" enctype="multipart/form-data">
    {#    {% csrf_token %}#}
    <p> 选择文件
        <input type="file" name="kouge">
    </p>
    <p><input type="text" name="oo"></p>
    <p>
        <input type="submit" value="提交头皮发麻">
    </p>

</form>
</body>
</html>

 

 

 

 

views文件

@csrf_exempt
def qigeming(request):
    if request.method =='POST':
        print(request.POST)
        file_obj =request.FILES.get('kouge')
        print(file_obj,type(file_obj))
        with open(file_obj.name,'wb')as f:
            for line  in file_obj:
                f.write(line)
        return HttpResponse('oo')
    return render(request,'qigeming.html')

  

 

 

posted @ 2018-05-29 16:50  萌哥-爱学习  阅读(203)  评论(0编辑  收藏  举报