python - Django upload_to 在 MEDIA_ROOT 之外

标签 python django security upload media

我的部署脚本覆盖了媒体和源目录,这意味着我必须将上传目录移出媒体目录,并在提取上传文件后替换它。

如何指示 django 上传到/uploads/而不是/media/?

到目前为止,我不断收到 django 可疑操作错误! :(

我想另一种解决方案可能是符号链接(symbolic link)?

非常感谢, 托比。

最佳答案

我做了以下事情:

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

关于python - Django upload_to 在 MEDIA_ROOT 之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1729051/

相关文章:

php - 什么时候需要在 PHP 中使用 Classes

javascript - python : Setting cookie into another website

python - Where 函数忽略 Nan

python - Django:如何声明项目范围的模板上下文处理器?

Javascript 安全风险?

php - 如何生成好的盐——我的函数是否足够安全?

python - Pandas:追加行副本,仅更改多列中大于允许拆分 bin 值的最大值的值

python - 提取字符串的一部分

python - 在 CentOs 服务器上导入 GeoIP 时出现 python 错误

python - 如何在 Django 中编写此插入语句?