Django upload_to outside of MEDIA_ROOT(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 之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Django upload_to 在 MEDIA_ROOT 之外
基础教程推荐
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
