ValueError-The 'image' attribute has no file associated with it. Error during template rendering

(Amir) #1
0 Likes

(Basil Jose) #2

the issue is due to no file is linked to ImageField, place {{ show.image.url }} in an if condition like,

{% if show.image %}
   {{ show.image.url }} 
{% endif %}

Verify your file linking is working properly. you may add default value in ImageField as,

avatar = models.ImageField(upload_to='avatars/', null=True, blank=True, default='/static/img/default-user.png') 

or you may change your custom property like

@property
def image_url(self):
    if self.image:
        return self.image.url
    return '#'
1 Like