django store image in database

泄露秘密 提交于 2019-11-27 17:49:26

问题


Does anyone know if there's an out-of-the box way of storing images directly in the database vs. using ImageField model type that simply uploads it to the MEDIA_ROOT. And if there is, how does one serve those images then?

Cheers


回答1:


No, there isn't. And for good reason. It's horribly inefficient to store and serve images from the database. Store them on the filesystem, and serve them directly from Apache.




回答2:


There is a nice solution here: http://djangosnippets.org/snippets/1305/ it stores content in a database blob.




回答3:


It seems there is no built-in BlobField in Django. However, there is one available here. I'm not sure if it supports all backends, but it might work for you. With that, you could write up a form & view that uploades the image as an attachment and stores it as a blob in the database.



来源:https://stackoverflow.com/questions/3771279/django-store-image-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!