zoukankan      html  css  js  c++  java
  • 西游之路——python全栈——上传文件

     1 from django.shortcuts import render,HttpResponse
     2 
     3 def upload(request):
     4     if request.method == 'GET':
     5         return render(request,'upload.html')
     6     else:
     7         user = request.POST.get('user')
     8         img = request.FILES.get('img')
     9         # img为对象(文件名称,大小,内容)
    10         f = open(img.name,'wb')
    11         # 不能一次性拿到内容,用循环一块一块的拿
    12         for line in img.chunks():
    13             f.write(line)
    14         f.close()
    15 
    16         return HttpResponse('............')
    Views.py操作

    HTML操作

     1 <form action="/upload.html/" method="POST" enctype="multipart/form-data">
     2     {% csrf_token %}
     3     <input type="text" name="user" />
     4     {# 上传按钮定制 #}
     5     <div style="position:relative">
     6         <a>NB上传</a>
     7         <input type="file" name="img" style="opacity:0; position:absolute;top:0;left:0;" />
     8     </div>
     9     <input type="submit" value="提交" />
    10 </form>

    — 文件上传

      — 普通上传

         —  自定义页面上传按钮

      — 基于form做上传

      — Ajax上传文件????

  • 相关阅读:
    主流的Nosql数据库的对比
    CCF考试真题题解
    排序
    2017-10-03-afternoon
    POJ——T 2728 Desert King
    51Nod——T 1686 第K大区间
    POJ——T 2976 Dropping tests
    2017-10-02-afternoon
    入参是小数的String,返回小数乘以100的String
    银联支付踩过的坑
  • 原文地址:https://www.cnblogs.com/Lujun1028/p/9614402.html
Copyright © 2011-2022 走看看