【问题标题】:Django: Could not parse the remainder: '"{%' from '"{%'Django:无法解析余数:来自 '"{%' 的 '"{%'
【发布时间】:2019-07-13 13:24:53
【问题描述】:

我正在使用 Django,但出现“模板渲染期间出错”:“无法解析剩余部分:'”{%' from '“{%'”。 这是导致问题的代码行:

{% with memberName="Java" memberPhoto="{% static 'sbs/images/avatar.jpg' %}" memberYear=80 memberBio="Lorem ipsum dalas dolores blabla" %} {% include "sbs/_member.html" %} {% endwith %}

这是由于图像而发生的,但是我怎样才能将图像作为变量放在这里而不会出现此错误?

提前致谢!

【问题讨论】:

    标签: django


    【解决方案1】:

    你不能嵌套{% ... %}s。先使用static标签的as子句将静态URL存入一个变量:

    {% static 'sbs/images/avatar.jpg' as avatar %}
    {% with memberName="Java" memberPhoto=avatar memberYear=80 memberBio="Lorem ipsum dalas dolores blabla" %}
    {% include "sbs/_member.html" %}
    {% endwith %}
    

    【讨论】:

      猜你喜欢
      • 2015-12-31
      • 2013-10-04
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2013-11-22
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多