Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用objectid从image.file获取图像_Python_Django_Image_Mongodb_Mongoengine - Fatal编程技术网

Python 使用objectid从image.file获取图像

Python 使用objectid从image.file获取图像,python,django,image,mongodb,mongoengine,Python,Django,Image,Mongodb,Mongoengine,我对mongoengine有问题。我在image.files集合中获取图像的objectid。如何在django中获取图像,就像image.files.objects(pk=objectid.first()? 是否有用于此的API?您只需查询网格id并返回匹配的文档,如下所示: class TestImage(Document): image = ImageField() TestImage.drop_collection() t = TestImage() t.image1.pu

我对mongoengine有问题。我在image.files集合中获取图像的objectid。如何在django中获取图像,就像image.files.objects(pk=objectid.first()
是否有用于此的API?

您只需查询
网格id
并返回匹配的文档,如下所示:

class TestImage(Document):

    image = ImageField()

TestImage.drop_collection()

t = TestImage()
t.image1.put(open(TEST_IMAGE_PATH, 'rb'))
t.save()

test = TestImage.objects.first()
grid_id = test.image1.grid_id

self.assertEqual(1, TestImage.objects(image1=grid_id).count())