考慮我們有一個模型BinaryField:from django.db import modelsimport hashlibclass Target(models.Model): # ... image = models.BinaryField(max_length=(1<<24)-1) # ... def __str__(self): return hashlib.md5().update(self.image).hexdigest()上面的代碼是否正確計算了圖像的 MD5 摘要?或者里面是否有一些方法或變量BinaryField來獲取傳遞給update()方法的內存?更新:當我嘗試:>>> from pathlib import Path>>> t = Target(image=Path('../../Experiments/LoginError2.jpg').read_bytes())>>> t我收到以下錯誤:AttributeError: 'NoneType' object has no attribute 'hexdigest'那么我做錯了什么?
如何從 Django 中的 BinaryField 獲取字節(jié)?
函數(shù)式編程
2021-09-28 17:53:14