標籤:display response type BMI 按鈕 spl art ide Enctype
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上傳檔案????
西遊之路——python全棧——上傳檔案