设为首页 加入收藏

TOP

Django 视图层(三)
2018-11-08 20:10:50 】 浏览:301
Tags:Django
gs, **kwargs): print(request) print(args) print(kwargs) # 可以写类似装饰器的东西,在前后加代码 obj=super().dispatch(request, *args, **kwargs) return obj def get(self,request): return render(request,"index.html") def post(self,request): return HttpResponse('post')

七.简单文件上传

前端

<form action="" method="post" enctype="multipart/form-data">
{# <form action="" method="post" enctype="application/x-www-form-urlencoded"> #}
    <input type="file" name="myfile">
    <input type="text" name="password">
    <input type="submit" value="提交">
</form>

后台

def fileupload(request):
    if request.method == "GET":
        return render(request,"fileupload.html")
    if request.method == "POST":
        # 从字典种根据名字,把文件取出来
        myfile = request.FILES.get("myfile")
        name = myfile.name
        # 打开文件,把上传过来的文件保存到本地
        with open(name,"wb") as f:
            for line in myfile:
                f.wirte(line)
        return HttpResponse('ok')
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python入门必学:如何操作输入输.. 下一篇模块(包、库)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目