Graphene Django文件字段获取绝对路径

Graphene Django文件字段获取绝对路径,django,graphene-django,Django,Graphene Django,我的Django模型中有一个图像场,我试图得到从石墨烯输出的图像场的绝对路径,以便连接到我的客户机 class ProfileType(DjangoObjectType): class Meta: model = Profile def resolve_avatar(self, info, **kwargs): print(info.context.build_absolute_uri(self.avatar)) 我没有获得绝对文件字段路径。如果Profile

我的Django模型中有一个图像场,我试图得到从石墨烯输出的图像场的绝对路径,以便连接到我的客户机

class ProfileType(DjangoObjectType): 
     class Meta: model = Profile

     def resolve_avatar(self, info, **kwargs):

    print(info.context.build_absolute_uri(self.avatar))

我没有获得绝对文件字段路径。

如果Profile.avatar是ImageField,则应使用self.avatar.url而不是self.avatar:

info.context.build_absolute_uri(self.avatar.url)