Can't get sorl.thumbnail to work

44 views
Skip to first unread message

DF

unread,
May 16, 2012, 11:17:15 PM5/16/12
to Django users
This is my first time using this app and I can't seem to get it
working within the template. No errors. It's just that nothing shows
up (which is obviously an error).

Here's the snippet from the template:

{% extends 'base.html' %}
{% load thumbnail %}
{% block page_title %}User Profile{% endblock %}
{% block headline %}User profile for {{profile.user.username}}{%
endblock %}


{% block content %}
{% if profile.user.profile_pic %}
{% thumbnail item.image "50x50" crop="center" as im %}
<img src="{{ profile.profile_pic.url }}"
width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
{% endif %}


Something to note. In my models file, the "from sorl.thumbnail import
ImageField" is shaded out using PyCharm, so I'm curious as to whether
that's affecting it (although the docs say that sorl.thumbnail's
ImageField is not required). Also, using django-profiles and django-
registration, but everything with those is working smoothly.

Any help greatly appreciated as this is a stickler.

Irfan Baig

unread,
May 17, 2012, 1:43:34 AM5/17/12
to django...@googlegroups.com
    {% if profile.user.profile_pic %}
    {% thumbnail item.image "50x50" crop="center" as im %}
        <img src="{{ profile.profile_pic.url }}"
width="{{ im.width }}" height="{{ im.height }}">
    {% endthumbnail %}
    {% endif %}


Looks like you have a lot of mistakes in the variables you are referencing above. Your first {% if %} tag refers to profile.user.profile_pic, though I'm almost certain you want to reference profile.profile_pic.

Also, your thumbnail tag should look like this:
{% thumbnail profile.profile_pic "50x50" crop="center" as im %}

Finally, since you are assigning the thumbnail to the im var, you'd want the image src to point to {{ im.url }}, not {{ profile.profile_pic_url }}.

Irfan Baig

unread,
May 17, 2012, 1:47:30 AM5/17/12
to django...@googlegroups.com
Additionally, be sure to set THUMBNAIL_DEBUG = True in your settings file, as this will make sorl spit debug info. See the documentation here:
http://thumbnail.sorl.net/reference/settings.html


DF

unread,
May 17, 2012, 1:58:57 AM5/17/12
to django...@googlegroups.com
Like a charm!

Thanks for your patience. I was working on this, my first django project, for months then put it away two months ago when things got too hectic. Still brushing off the cobwebs with some things,

Many, many thanks.
Reply all
Reply to author
Forward
0 new messages