在 python 的 django 中怎麼上傳檔案並且搬移位置呢?
做法有很多種
我是參考別人作法:
https://www.cnblogs.com/linxiyue/p/7442232.html
我提供我的作法給大家參考
#使用 FileSystemStorage from django.core.files.storage import FileSystemStorage #這邊是在 view 的功能裡面喔 #這邊是在 view 的功能裡面喔 #這邊是在 view 的功能裡面喔 #檔案位置 baseDir = 'testupload/' 在 view 中request取得上傳檔案物件 matFile = request.FILES['file'] #複製檔案到自己想要位置 #新增 FileSystemStorage 並且設定資料夾 fs = FileSystemStorage(location=baseDir) #儲存動作 matFile.name 是檔案名稱 fs.save(matFile.name, matFile)
留言板
歡迎留下建議與分享!希望一起交流!感恩!