本文介紹了Django upload_to 在 MEDIA_ROOT 之外的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我的部署腳本覆蓋了媒體和源目錄,這意味著我必須將上傳目錄移出媒體目錄,并在提取上傳文件后替換它.
My deployment script overwrites the media and source directories which means I have to move the uploads directory out of the media directory, and replace it after the upload has been extracted.
如何指示 django 上傳到/uploads/而不是/media/?
How can I instruct django to upload to /uploads/ instead of /media/?
到目前為止,我不斷收到 django 可疑操作錯誤!:(
So far I keep getting django Suspicious Operation errors! :(
我想另一種解決方案可能是符號鏈接?
I suppose another solution might be a symlink?
非常感謝,托比.
推薦答案
我做了以下:
from django.core.files.storage import FileSystemStorage
upload_storage = FileSystemStorage(location=UPLOAD_ROOT, base_url='/uploads')
image = models.ImageField(upload_to='/images', storage=upload_storage)
UPLOAD_ROOT
在我的 settings.py
文件中定義:/foo/bar/webfolder/uploads
UPLOAD_ROOT
is defined in my settings.py
file: /foo/bar/webfolder/uploads
這篇關于Django upload_to 在 MEDIA_ROOT 之外的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!