Django upload_to在MEDIA_ROOT之外 [英] Django upload_to outside of MEDIA_ROOT
问题描述
我的部署脚本会覆盖媒体和源目录,这意味着我必须将上传目录移出媒体目录,并在上传提取后将其替换。
如何指示django上传到/ uploads /而不是/ media /?
到目前为止,我不断得到django可疑操作错误! :(
我想另一个解决方案可能是一个符号链接?
非常感谢,
Toby。
我做了以下:
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)
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. How can I instruct django to upload to /uploads/ instead of /media/? So far I keep getting django Suspicious Operation errors! :( I suppose another solution might be a symlink? Many thanks,
Toby. I did the following: 这篇关于Django upload_to在MEDIA_ROOT之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! UPLOAD_ROOT
在我的
settings.py
文件中定义: / foo / bar / webfolder / uploads
p> 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
is defined in my settings.py
file: /foo/bar/webfolder/uploads