Dani Mateo Dani Mateo - 10 months ago 63
Python Question

Django userena check if mugshot is set

Ok so this is the models.py of userena. Can i check using template tags in html if mugshot is set? The first if statement checks if the mugshot is uploaded.

def get_mugshot_url(self):
Returns the image containing the mugshot for the user.

The mugshot can be a uploaded image or a Gravatar.

Gravatar functionality will only be used when
``USERENA_MUGSHOT_GRAVATAR`` is set to ``True``.

``None`` when Gravatar is not used and no default image is supplied

# First check for a mugshot and if any return that.
if self.mugshot:
return self.mugshot.url

# Use Gravatar if the user wants to.
if userena_settings.USERENA_MUGSHOT_GRAVATAR:
return get_gravatar(self.user.email,

# Gravatar not used, check for a default image.
if userena_settings.USERENA_MUGSHOT_DEFAULT not in ['404', 'mm',
return userena_settings.USERENA_MUGSHOT_DEFAULT
return None

Answer Source

You could simply replicate the first if statement in the template on the user profile's instance. Something like

{% if profile.mugshot %}
{% endif %}