Django ModelSerializer with ImageFIeld and HTTPS

I have a news model with an image, and this news can be downloaded via the JSON REST API. The server is signed with a certificate from the Authority, and all requests must be performed using https.

My problem is that ModelSerializer serializes ImageField with http, not https. How to change this?

Here is a summary of sample code and output:

#myProject/models.py
class News(models.Model):
    image = models.ImageField()

#myProject/serializers.py
class NewsSerializer(serializers.ModelSerializer):
    class Meta:
        model = News
        fields = ('image')

#request for a news
https://myDomain/news/the-news-id-here/

#current output
{
    "image": "http://myDomain/media/news/imageName.jpg"
}

#wanted output
{
    "image": "https://myDomain/media/news/imageName.jpg"
}

Thanks david

+4
source share

Source: https://habr.com/ru/post/1609939/


All Articles