在原来下载图片基础上:
1.在设置文件中定义好图像名称字段
IMAGES_NAME_FIELD = 'image_names'
2.在images.py文件中修改名称
类变量中添加:
DEFAULT_IMAGES_URLS_FIELD = 'image_urls' DEFAULT_IMAGES_RESULT_FIELD = 'images' IMAGES_NAME_FIELD = 'image_names'
初始化:
self.images_name_field = settings.get( resolve('IMAGES_NAME_FIELD'), self.IMAGES_NAME_FIELD )
将file_name内容携带出去
def get_media_requests(self, item, info): return [Request(x, meta={'file_name': item.get(self.images_name_field, '')}) for x in item.get(self.images_urls_field, [])]
修改image_guid就ok了
image_guid = request.meta['file_name']