I am trying to read image from url and save into db.
image = Image()
name = urlparse(imgurl).path.split('/')[-1]
image.bild.save(name, File(urllib2.urlopen(imgurl).read()), save=False)#error line
image.von_location = location
image.save()
this is my Image model
class Image(models.Model):
von_location= models.ForeignKey(Location,related_name="locations_image",default=0)
bild = models.ImageField(upload_to=locationimage,default='')
def __unicode__(self):
return self.bild.name
the error below is coming when i try to call the save() method of image file.
AttributeError: str has no attribute name
name is just a name of image as i read this here https://docs.djangoproject.com/en/dev/ref/files/file/
this is the screenshot of error message

return self.bildreturn ?image.bild.save(name, File(urllib2.urlopen(imgurl)), save=False)? urllib2.urlopen is supposed to return a file-like object already. Also, the stack trace seems to have different variable names than the listed code