【发布时间】:2016-06-18 01:38:40
【问题描述】:
我有一个具有 Image 字段的模型:
class Foo(models.Model):
image = models.ImageField(upload_to = "bar", blank = True)
我正在使用 urllib 通过互联网下载图像,如下所示:
urllib.urlretrieve(img_url, img_path)
现在我想将图像字段指向保存为 img_path 的下载图像。我曾尝试使用PIL 中的Image.open() 首先打开文件并指向它,然后使用django.core.files.File 指向它并使用obj.image.save(File(open(file_path))),但它们似乎不起作用。是否有替代方法来实现这一点?
【问题讨论】:
标签: python django python-2.7 django-models