Django-avatar is a reusable application for handling user avatars. It has the ability to default to Gravatar if no avatar is found for a certain user. Django-avatar automatically generates thumbnails and stores them to your default file storage backend for retrieval later.
If you have pip installed, you can simply run the following command to install django-avatar:
pip install django-avatar
Included with this application is a file named setup.py. It’s possible to use this file to install this application to your system, by invoking the following command:
python setup.py install
Once that’s done, you should be able to begin using django-avatar at will.
To integrate django-avatar with your site, there are relatively few things that are required. A minimal integration can work like this:
List this application in the INSTALLED_APPS portion of your settings file. Your settings file will look something like:
INSTALLED_APPS = (
# ...
'avatar',
)
Add the avatar urls to the end of your root urlconf. Your urlconf will look something like:
urlpatterns = patterns('',
# ...
(r'^avatar/', include('avatar.urls')),
)
Somewhere in your template navigation scheme, link to the change avatar page:
<a href="{% url 'avatar_change' %}">Change your avatar</a>
Wherever you want to display an avatar for a user, first load the avatar template tags:
{% load avatar_tags %}
Then, use the avatar tag to display an avatar of a default size:
{% avatar user %}
Or specify a size (in pixels) explicitly:
{% avatar user 65 %}
To begin using these template tags, you must first load the tags into the template rendering system:
{% load avatar_tags %}
There are a number of settings available to easily customize the avatars that appear on the site. Listed below are those settings:
This application does include one management command: rebuild_avatars. It takes no arguments and, when run, re-renders all of the thumbnails for all of the avatars for the pixel sizes specified in the AUTO_GENERATE_AVATAR_SIZES setting.