Using sorl thumbnail and easy thumbnails in the same template

At times you need to use both sorl.thumbnail and easy_thumbnails in the same template. Both of these apps define a thumbnail template tag from a thumbnail template module meaning that you will be able to use one or the other but not both.

🚀 2017 Update: there are easier ways to get this working with more recent versions of Django. I've updated the post to first show the "newer" approach to working with template libraries that overlap then I've included the "older" approach I originally took.

New Approach

You can now use thelibraries dictionary from the default template backend in your settings.py to re-label your template libraries and avoid naming conflicts:

settings.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(PYTHON_PATH, 'templates/'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            'libraries': {
                'sorl_thumbnail': 'sorl.thumbnail.templatetags.thumbnail',
                'easy_thumbnails': 'easy_thumbnails.templatetags.thumbnail',
            },
        },
    },
]

and within your template:

{% load sorl_thumbnail %}

Of course, this means you can’t use both libraries’ {% thumbnail %} in the same template, but you can load both template libraries successfully in the same project.

Original Solution

At times you need to use both sorl.thumbnail and easy_thumbnails in the same template. Both of these apps define a thumbnail template tag from a thumbnail template module meaning that you will be able to use one or the other but not both. To get around this, you can install a great app called django-smart-load-tag which augments the default {% load %} tag and allows for much more flexible importing of template tags.

After installing django-smart-load-tag with pip install django-smart-load-tag add it to your INSTALLED_APPS:

settings.py
INSTALLED_APPS = (
 #...,
 'smart_load_tag'
)

open your template and do the following:

{% load smart_load %}
{% load thumbnail from sorl.thumbnail as sorl_thumbnail %}
{% load thumbnail from easy_thumbnails as easy_thumbnail %}

...

{% sorl_thumbnail image.image "100x100" as im %}
<img src='{{ im.url }}' />
{% endthumbnail %}

...

<img src='{% easy_thumbnail image.image "100x100" %}' />

You now have both options!