Django TemplateSyntax Error with Sorl-thumbnail
我试图让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的本地主机上安装的 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.
我可能是错的,但我认为您不需要
{% endthumbnail %}
标签。I might be wrong, but I don't think you need the
{% endthumbnail %}
tag.问题也可能出在加载模板标签上。
我在基本 html 中执行
{% loadthumbnail %}
。当我在继承的 html 中调用下面的代码时,得到了同样的错误。
请参阅此讨论 关于在 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.
See this discussion about loading template tags in base.html
我刚刚在 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'sthumbnail
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.