[Fixed]-How to put default avatar for a user

1👍

Try following:

 {% if not each_model.Profile_image %}
       <img src="{{MEDIA_URL}}/Profile_image/deafult-profile-image.png"/>
            <hr>
        {% else %}
             <img src="{{MEDIA_URL}}{{each_model.Profile_image}}"style="width:300px; height:200px; display:block; margin-left:auto;margin-right:auto">
                <hr>
    {% endifequal %}

But I would suggest you to have a method for your user model which will return the user avatar and use that method in template:

# in MyUser model
def get_avatar(self):
   if not self.Profile_image:
       return "YOUR DEFAULT IMAGE"
   else:
       return return os.path.join(settings.MEDIA_URL, self.Profile_image.name)

# and in template:
<img src={each_model.get_avatar} />

Leave a comment