Django TemplateSyntax Error with Sorl-thumbnail

发布于 2024-11-02 08:39:18 字数 905 浏览 6 评论 0原文

我试图让 Sorl-thumbnail 在我的临时服务器上运行,但我遇到了 TemplateSyntaxError,因为该应用程序在本地主机上运行良好,所以我遇到了 TemplateSyntaxError 。

错误出现在 {% endthumbnail %}

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

任何帮助将不胜感激。谢谢!

{% 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 %}

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 %}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

游魂 2024-11-09 08:39:18

您的本地主机上安装的 sorl-thumbnail 版本可能比临时服务器上安装的版本旧。 endthumbnail 标签是最近添加的,作为主要重写的一部分。

如果您发现需要升级,您可能会发现设置THUMBNAIL-DEBUG 有助于追踪其他问题。

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.

临走之时 2024-11-09 08:39:18

我可能是错的,但我认为您不需要 {% endthumbnail %} 标签。

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

尸血腥色 2024-11-09 08:39:18

问题也可能出在加载模板标签上。

我在基本 html 中执行 {% loadthumbnail %}
当我在继承的 html 中调用下面的代码时,得到了同样的错误。

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

请参阅此讨论 关于在 base.html 中加载模板标签

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

顾忌 2024-11-09 08:39:18

我刚刚在 Mezzanine 中使用 SORL Thumbnail 时遇到了这个问题。显然,Mezzanine 会加载它自己的缩略图,因此如果您 {% loadthumbnail mezzanine_tags %},mezzanine 的 thumbnail 就会接管 SORL 的 Thumbnail 标签。但是,如果你反转它{% load mezzanine_tagsthumbnail %},它就可以正常工作。

经验教训:确保您正在使用的其他库不会无意中接管,并且为了安全起见,可以最后加载缩略图。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文