Django upload_to 在 MEDIA_ROOT 之外
- 作者: 老实人妙勇
- 来源: 51数据库
- 2022-10-25
问题描述
我的部署脚本覆盖了媒体和源目录,这意味着我必须将上传目录移出媒体目录,并在提取上传文件后替换它.
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
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
