[英]Expected string or buffer
I am trying to get the related image URL from my model 我正在尝试从模型中获取相关的图像URL
class DetailSerializer(serializers.ModelSerializer):
image = serializers.SerializerMethodField("get_related_image_url")
etc
def get_related_image_url(self, obj):
request = self.context.get('request', None)
print(request.build_absolute_uri(obj.image()))
Error: 错误:
expected string or buffer 预期的字符串或缓冲区
/Users/user/Documents/workspace/demo/django-env/lib/python2.7/site-packages/django/http/request.py in build_absolute_uri
"""
Builds an absolute URI from the location and the variables available in
this request. If no location is specified, the absolute URI is built on
``request.get_full_path()``.
"""
if not location:
location = self.get_full_path()
if not absolute_http_url_re.match(location): ...
current_uri = '%s://%s%s' % ('https' if self.is_secure() else 'http',
self.get_host(), self.path)
location = urljoin(current_uri, location)
return iri_to_uri(location)
def _is_secure(self):
Why do I get this error? 为什么会出现此错误?
obj.image()
似乎返回的不是字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.