django-rest-framework Manually modify the return value of the image field (the method of changing the source code)

django-rest-framework manually modify the return value of the image field

1. Enter rest-framework.fields

  • There is an ImageField (FileField) in it, enter FileField, find its to_represent method, or rewrite it in ImageField, the return url inside is the address of the returned ImageField object
  • ImageField.url is to return the full url path
  • ImageField.name is the url path returned to the store
  • After changing here, the return value of rest-framework's serializer will change.

Mainly because: I have a requirement in my project to put a complete url to reference external images, while django-rest-framework can only return the url he spliced ​​to you

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324777270&siteId=291194637