Django upload_to 在 MEDIA_ROOT 之外

Django upload_to outside of MEDIA_ROOT(Django upload_to 在 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 之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to find element by part of its id name in selenium with python(如何使用python在selenium中通过其id名称的一部分查找元素)
NoSuchElementException: Message: Unable to locate element while trying to click on the button VISA through Selenium and Python(NoSuchElementException:消息:尝试通过 Selenium 和 Python 单击 VISA 按钮时无法找到元素) - IT屋-程序员软件开发技术分
Selenium not able to click on Get Data button on using Python(Selenium 在使用 Python 时无法单击“获取数据按钮)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python(selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素不可点击
Selenium Compound class names not permitted(不允许使用硒化合物类名称)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element while trying to click Next button with selenium(selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试使用 selenium 单