Django拇指后端的自定义存储。
django-thumborstorage的Python项目详细描述
用于thumbor后端的django自定义存储。
此应用程序提供2个类ThumborStorage和ThumborMigrationStorage。最后一个 是一个可以用于Imagefield初始值的存储,可以使用所需的FileSystemStorage。 在不批量移动它们的情况下迁移到thumbor。这样的话,詹戈继续发球 从文件系统中删除,直到更改该字段上的图像。
安装
pip install django-thumborstorage
用法
设置.py
在INSTALLED_APPS中添加django_thumborstorage。
并设置以下各项:
THUMBOR_SERVER='http://localhost:8888'THUMBOR_SECURITY_KEY='MY_SECURE_KEY'# This may be a different host than THUMBOR_SERVER# only reachable by your Django server.THUMBOR_RW_SERVER='http://localhost:8888'
型号.py
只需在要用拇指管理的imagefield中设置storage参数即可:
fromdjango_thumborstorage.storagesimportThumborStorageclassStuff(models.Model):defupload_path(instance,filename):return'stuffs/%s'%filenamephoto=models.ImageField(upload_to=upload_path,storage=ThumborStorage(),height_field='photo_height',width_field='photo_width')photo_height=models.IntegerField(blank=True,null=True)photo_width=models.IntegerField(blank=True,null=True)
在代码中
您可以使用:
my_stuff.photo.storage.key(my_stuff.photo.name)
当原始文件存储在thumbor上时,这对于generate_url()和Django-thumbor非常有用。因此, 可以将密钥作为url参数传递。
更改日志
1.11.0
- 放弃对django<;1.11和python 3.4的支持。
- 从依赖项中删除mock。
0.92.2
- 修复readonly_to_rw_url()以管理URL中的后缀。
0.92.1
- 在发布图像时处理拇指服务器响应的状态代码。
0.92.0
- 添加了实验性的python 3.4支持(感谢charlie 123)
- 修复了django<;1.7的断开支持(感谢rizziepit)
- 在文件名中添加了Unicode支持(感谢rizziepit)
0.91.6
- 添加storages.readonly_to_rw_url(),该函数用于转换rw url中的只读拇指url。
0.91.5
- 使用拇指服务器生成原始文件URL。
向后不相容性
- THUMBOR_SERVER和THUMBOR_SECURITY_KEY在设置中是必需的。
0.91.4
- 添加ThumborStorage.key(name)以从名称中检索thumbor uuid。
0.91.3
向后不相容性
- THUMBOR_WRITABLE_SERVER设置替换为THUMBOR_RW_SERVER,因为它现在用于检索
原始文件。
待办事项
- 放置