【问题标题】:image in block of StreamField is not recognizedStreamField 块中的图像无法识别
【发布时间】:2018-09-30 21:20:31
【问题描述】:

显示此错误:

'image' 标签的格式应该是 {% image self.photo max-320x200 [ custom-attr="value" ... ] %} 或 {% image self.photo max-320x200 as img %}

第 19 行 {% image block.value as mein_bild %}

我的模板:

{% extends "base.html" %}
{% load static wagtailcore_tags wagtailimages_tags %}

{% block content %}

  <div class="notiert">
    <header>
      <h1>{{ page.title }}</h1>
    </header>
   <div class="body">
     {{ page.kurzfassung|richtext }}
     <p>{{ page.first_published_at }}</p>
     {% for block in self.notiert_feld %}
        {% if block.block_type == 'image' %}
           <p>in if image {{ block.value }}</p> 
           {% image block.value as mein_bild %}
           <img {{ mein_bild }} width=530 > 
        {% else %}
          {{ block.value }}
        {% endif %}
    {% endfor %}
    </div>    
  </div>

{% 端块 %}

第 18 行我用于调试。如果我删除第 19 和 20 行,则会显示图像的名称。

【问题讨论】:

    标签: django wagtail wagtail-streamfield


    【解决方案1】:

    我以为我尝试了这个变体并得到了错误。但现在它起作用了。

    {% extends "base.html" %}
    {% load static wagtailcore_tags wagtailimages_tags %}
    
    
    
    {% block content %}
    
    
      <div class="notiert">
        <header>
          <h1>{{ page.title }}</h1>
        </header>
          <div class="body">
             {{ page.kurzfassung|richtext }}
             <p>{{ page.first_published_at }}</p>
             {% for block in self.notiert_feld %}
                {% if block.block_type == 'image' %}
                    {% image block.value width-530 %}
                {% else %}
                    {{ block.value }}
                {% endif %}
             {% endfor %}
        </div>    
      </div>
    
    
    
    
    {% endblock %}
    

    感谢您的回答!

    【讨论】:

      【解决方案2】:

      https://docs.wagtail.io/en/stable/topics/images.html 中所述,您需要包含一个调整大小规则来指示图像应呈现的大小。如果您不希望调整图片大小,请使用original(但请记住,如果编辑者上传过大的图片,它可能会破坏您的页面布局和/或浪费带宽):

      {% image block.value original as mein_bild %}
      

      【讨论】:

        猜你喜欢
        • 2021-03-30
        • 2015-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多