我的Photo
模型面临一种非常奇怪的行为,包含ImageField
。
当我执行以下代码时:
photos = Photo.objects.all()
for p in photos:
print p.id
我在Django显示大约36680个ID后出现此错误:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/me/Sites/django/mysite/forum/views.py", line 286, in photos_search
for p in photos:
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 139, in _result_iter
self._fill_cache()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 941, in _fill_cache
self._result_cache.append(next(self._iter))
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 327, in iterator
obj = model(*row_data)
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 417, in __init__
signals.post_init.send(sender=self.__class__, instance=self)
File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py", line 379, in update_dimension_fields
width = file.width
File "/Library/Python/2.7/site-packages/django/core/files/images.py", line 15, in _get_width
return self._get_image_dimensions()[0]
File "/Library/Python/2.7/site-packages/django/core/files/images.py", line 25, in _get_image_dimensions
self.open()
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py", line 76, in open
self.file.open(mode)
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py", line 46, in _get_file
self._file = self.storage.open(self.name, 'rb')
File "/Library/Python/2.7/site-packages/django/core/files/storage.py", line 36, in open
return self._open(name, mode)
File "/Library/Python/2.7/site-packages/django/core/files/storage.py", line 159, in _open
return File(open(self.path(name), mode))
IOError: [Errno 2] No such file or directory: u'<path_to_my_photo>'
Weirder,当我从id = 35000开始时,它以相同的方式崩溃,但是,在显示36668个ID之后......
photos = Photo.objects.filter(id__gte=35000)
for p in photos:
print p.id
当我单独查询36668th或36680th对象时,一切似乎都没问题。
我无法理解为什么当我刚看完照片列表时Django试图获得“get_image_dimensions
”?
有什么想法吗?
答案 0 :(得分:0)
似乎其中一个Photo
对象的图像字段保存为'<path_to_my_photo>'
,但在磁盘上不存在。