【问题标题】:Wagtail feed_image not Displaying on Index Page鹡鸰 feed_image 未显示在索引页面上
【发布时间】:2017-07-23 07:03:45
【问题描述】:

我似乎无法弄清楚为什么我的 feed_image 在被称为 {{ self.feed_image }} 时可以在页面上工作,但是在尝试添加到索引页面时,它不会显示 - 只是显示一个损坏的图像。

sn-p

@register.inclusion_tag(
    'tags/_product-snippets.html',
    takes_context=True
)
def product_snippets(context, calling_page):
    pages = calling_page.get_children().live()
    return {
        'pages': pages,
        # required by the pageurl tag that we want to use within this template
        'request': context['request'],
    }

标签

<div class="row">
    {% for page in pages %}
      <div class="col-md-3 col-sm-4 col-xs-12">
        <div class="shop-item-container-in">
          {% image page.feed_image as img %} 
          <img src="{{ img.url }}" alt="{{ page.title }}" title="{{ page.title }}" class="img-responsive center-block shop-item-img-list-view"/>
        </div>
        <h4><a href="{% pageurl page %}">{{ page.title }}</a></h4>
        <a href="{% pageurl page %}" class="button button-md button-pasific hover-icon-wobble-horizontal mt25">More<i class="fa fa-shopping-basket"></i></a>
      </div>
    {% endfor %}
  </div>

html

...
{% product_snippets calling_page=self %}
...

【问题讨论】:

    标签: django django-models django-templates wagtail wagtail-snippet


    【解决方案1】:

    当您使用以下方法查询页面树时:

    pages = calling_page.get_children().live()
    

    您最初只会获得基本的Page 对象,这些对象由诸如title 和slug 之类的核心字段组成。这是出于性能原因 - 获取详细的页面内容需要对数据库进行额外的点击。要检索包括feed_image 在内的整页数据,请添加specific()

    pages = calling_page.get_children().live().specific()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多