Search code examples
djangoimagefield

Django ImageField updates but doesn't render changes


I have the following field:

logo = models.ImageField(_(u"Logo"), blank=True, null=True, upload_to=directory)

That is rendered like:

<img src="{{ logo.url }}"/>

When I change the logo, the new image is uploaded and I can see the logo field has changed in the database.

The problem is the template tries to render the old image. This URL is not valid anymore, and the image missing. This happens until I restart the server.

After restarting, it works perfectly. It's like logo.url value keeps somehow cached. What am I missing here?


Solution

  • Found the issue: this field belongs to a model connected one2one to Site , from Djago Sites framework.

    I added a call to Site.objects.clear_cache() after saving the changes on my model. Now it works!