I'm using django-imagekit to resize my user avatars and right now to display a default avatar (if the user didn't upload his/her avatar) I do this:
views.py
    try:
        usr_avatar = UsrAvatar.objects.get(user=request.user.id)        
    except UsrAvatar.DoesNotExist: 
        usr_avatar = UsrAvatar.objects.get(id='0')  
template.html
<img src="{{ usr_avatar.avatar_image.url }}" >
This works fine but every time a user didn't upload his/her avatar I'm hitting the database for the default avatar image.
Is there a way to eliminate hitting the database when the user doesn't have an avatar image loaded by somehow attributing the default image link to usr_avatar or just doing something in the template.html? Thank you!
 
     
    