[英]django upload file to custom location
Is it possible to upload a file in django using django's model.FileField()
to a location that's not relative to /media
?. 是否可以使用Django的
model.FileField()
将文件上传到与/media
不相关的位置? In my case upload an .html file to myproject/templates
. 就我而言,将.html文件上传到
myproject/templates
。
You cannot if I remember right, this kind of operation is in-secure. 如果我没记错的话,您不能保证这种操作是不安全的。 The file storage backend would warn it.
文件存储后端会发出警告。
You could either customize the storage backend, or upload to directory like /media/user_template
and set it in TEMPLATE_DIRS
. 您可以自定义存储后端,也可以上载到
/media/user_template
类的目录并在TEMPLATE_DIRS
设置。
If you only want to use dynamic templates, check django-dbtemplates as a DB-based solution. 如果只想使用动态模板,请检查django-dbtemplates作为基于DB的解决方案。
试试: models.FileField(upload_to = '...')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.