سؤال

I am using django-gravatar and I am wondering how to display a local image to use as a default image. Is there a way to do so?

I have read in the docs to use GRAVATAR_DEFAULT_IMAGE, but it does not seem to work specifying the path to the image within the static/ directory. Is it only for online images from other websites?

Thanks!

EDIT

I am using the following configuration:

STATIC_URL = '/static/'
GRAVATAR_DEFAULT_IMAGE = STATIC_URL + 'img/StartMyProjects_100.png'

Hack finally used to solve the problem:

<img class="media-object" src="
{% if profile.gravatar_email %}
    {% gravatar_for_email profile.gravatar_email %}
{% else %}
    /static/img/StartMyProjects_100.png
{% endif %}"
alt="{{ profile.full_name }}">

هل كانت مفيدة؟

المحلول

To solve the problem, as stated in the edited question, I actually used an if-else (in Django). Maybe someone knows a better way to do so, but this worked for me!

<img class="media-object" src="
{% if profile.gravatar_email %}
    {% gravatar_for_email profile.gravatar_email %}
{% else %}
    /static/img/StartMyProjects_100.png
{% endif %}"
alt="{{ profile.full_name }}">
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top