开发者

Django TemplateSyntax Error with Sorl-thumbnail

开发者 https://www.devze.com 2023-02-27 06:37 出处:网络
I\'m trying to get Sorl-thumbnail running on my staging server, but I\'m running into a TemplateSyntaxError which is throwing me since the app works fine on localhost.

I'm trying to get Sorl-thumbnail running on my staging server, but I'm running into a TemplateSyntaxError which is throwing me since the app works fine on localhost.

The error is coming in at {% endthumbnail %}

TemplateSyntaxError at /home/
Invalid block tag: 'endthumbnail', expected 'endif'

Any help would be greatly appreciated. Thanks!

{% load thumbnail %}

{%开发者_开发技巧 if picture.photo_medium %}
    <img src="{{AWS_URL}}{{picture.photo_medium}}" class="imagepage" width="400" height="300">
{% else %}
    {% if picture.photo_large|is_portrait %}
       <div class="portrait">
          {% thumbnail picture.photo_large "400" crop="center" as im %}
          <img src="{{AWS_URL}}{{ im }}">
       </div>
    {% else %}
       <div class="landscape">
          {% thumbnail picture.photo_large "400" crop="center" as im %}
          <img src="{{AWS_URL}}{{ im }}">
       </div>
    {% endif %}
{% endif %}


It is likely that you have an older version of sorl-thumbnail installed on your localhost than is installed on your staging server. The endthumbnail tag was added relatively recently as part of a major rewrite.

If you find that you need to upgrade you may find the setting THUMBNAIL-DEBUG helpful for tracking down other problems.


I might be wrong, but I don't think you need the {% endthumbnail %} tag.


The problem can also be with loading template tags.

I was doing {% load thumbnail %} in base html. When I call below code in inherited html, got same error.

{% thumbnail service_type.pic.image "100x100" crop="center" as im %}
   <img .....>
{% endthumbnail %} 

See this discussion about loading template tags in base.html


I just ran into this problem in using SORL Thumbnail in Mezzanine. Apparently Mezzanine loads it's own thumbnailer, so if you {% load thumbnail mezzanine_tags %}, mezzanine's thumbnail takes over from SORL's Thumbnail tag. However, if you reverse it {% load mezzanine_tags thumbnail %}, it works fine.

Lesson Learned: Make sure other libraries you're using aren't inadvertently taking over, and just to be safe maybe load thumbnail last.

0

精彩评论

暂无评论...
验证码 换一张
取 消