Код обидчика:
file_name = os.path.basename(image_url)
downloaded = urllib2.urlopen(image_url).read()
image_file = File(downloaded, name=file_name)
image_file.size = len( downloaded )
model = BlogPost()
model.image.save(file_name, image_file)
model.save()
Модель:
Класс BlogPost (models.Model): image = models.ImageField (upload_to = 'blog-image', help_text = 'Featureimage ', blank = True, null = True)
Я получаю следующее:
AttributeError: 'str' object has no attribute 'read'
Если удалить строку image_file.size:
AttributeError: 'str' object has no attribute 'name'
downloaded
заполнен, поэтому он успешно загрузил файл.
Что я делаю не так?