【问题标题】:to deal with saticfile's path in sorl-thumbnail在 sorl-thumbnail 中处理 saticfile 的路径
【发布时间】:2014-12-05 02:36:31
【问题描述】:

我想知道如何处理sorl-thumbnail中saticfile的路径

我的代码有错误:

无法解析余数:'{%' from '{%'

    {% load thumbnail %}
    {% thumbnail {% static 'img/logo.png' %} "100x80" format="PNG"   as im %}
    <img src="{{  im.url  }}" width="{{ im.width }}" height="{{ im.height }}">
    {% endthumbnail %}

【问题讨论】:

    标签: django sorl-thumbnail


    【解决方案1】:

    您不能在{% thumbnail %} 标记内使用{% static %} 标记。通常,您不能在任何其他标签中包含任何标签。

    确保在settings.py 文件中的TEMPLATE_CONTEXT_PROCESSORS 变量中包含'django.core.context_processors.static' 并尝试

    {% load thumbnail %}
    {% thumbnail STATIC_URL|add:'img/logo.png' "100x80" format="PNG"   as im %}
    <img src="{{  im.url  }}" width="{{ im.width }}" height="{{ im.height }}">
    {% endthumbnail %}
    

    【讨论】:

    • 我尝试了,但是收到了错误的请求(400)
    • 您确定您的TEMPLATE_CONTEXT_PROCESSORS 中有'django.core.context_processors.static' 吗?你的STATIC_URL 设置是什么?
    • 是的,我确定。我的静态网址:STATIC_URL = '/static/'
    • 除了 400 错误,您还有其他信息吗?
    • 我今天试试,没有任何反应。(没有 404,终端上没有消息)。如果我使用像“google.com.tw/images/srpr/logo11w.png”这样的网址图像,它可以工作,但static_url|add 不工作
    猜你喜欢
    • 2012-03-01
    • 2012-11-29
    • 2011-05-13
    • 2016-05-09
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    相关资源
    最近更新 更多