【发布时间】:2019-08-19 15:26:13
【问题描述】:
我的 Django 模型中有一个图像字段,我正在尝试获取 Graphene 输出的图像字段的绝对路径。我记得使用 HttpRequest.build_absolute_uri 获取文件/图像字段的绝对 uri。所以,我决定在 Graphene Django 中使用相同的功能:
class PersonType(DjangoObjectType):
def resolve_photo(self, info, **kwargs):
print(info.context) # WSGIRequest
print(info.context.build_absolute_uri(self.photo)) # Error here
return self.photo
class Meta:
model = Person
因为这里的请求不是Django的HttpRequest(是WSGI Request),所以我无法使用Django的request的一些实用功能。
有没有一种方法可以从 WSGIRequest 创建 HttpRequest,或者是否有其他方法可以在 Graphene Django 中构建完整的 URL?阅读互联网上的文档、源代码或资源,我无法找到解决问题的方法。
【问题讨论】:
标签: python django graphene-python