form中的 action 控制請求往什么地方提交
method 請求方式 如果不寫默認是get 請求
如果想傳文件 必須要把默認的urlencoded的改成enctype="multipart/form-date"
后端的代碼
def upload_file(request): if request.method == 'POST': print('path:',request.path) print('full_path:',request.get_full_path()) # print(request.FILES) file_obj = request.FILES.get('my_file') print(file_obj.name) with open(file_obj.name,'wb') as f: for line in file_obj.chunks(): f.write(line) return HttpResponse('OK') return render(request,'index.html')
前后端傳輸數據編碼格式contentType
urlencoded
對應的數據格式 :name=jason&password=666
后端獲取數據: rrequest.POST
formdate
form 表單傳輸文件的編碼格式
后端獲取文件格式數據:request.FILES
后端獲取普通鍵值對數據: request.POST