读取Django FileField的数据
我试图在将数据保存到数据库之前将其保存/下载到本地目录中,该数据库是在 Django FileField
中选择的。下载后,如何在 FileField
中维护所选文件的实例,以便将其保存到数据库中?
I am trying to save/download the data on local directory before save it to database, which is selected in Django FileField
. After download how do I maintain the instance of that selected file in that FileField
so that I can save it to database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否完全理解你的问题,但是......
默认情况下 Django 的 FileField 不会将文件存储在数据库中,而是存储在磁盘上(尽管可以使用自定义存储后端来完成:http://djangosnippets.org/snippets/1305/)。仅对文件的引用存储在数据库中(请参阅:http: //docs.djangoproject.com/en/dev/topics/files/#file-storage)。
如果您想自定义此行为,您应该查看文档: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#file-uploads
Not sure if i completely understand your problem, but ...
by default Django's FileField doesn't store the file in your database but on disk (though it can be done using a custom storage backend: http://djangosnippets.org/snippets/1305/). Only the reference to the file is stored in the database (See: http://docs.djangoproject.com/en/dev/topics/files/#file-storage).
If you want to customize this behavior you should take a look at at docs: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#file-uploads