我试图从context获取页面和请求,以便能够在块内使用分页。我得到的唯一背景是
context {'self': None, 'value': None}
甚至可以在streamfield块内进行分页吗?在
class CustomStaticBlock(blocks.StaticBlock):
def get_context(self, value):
context = super(CustomStaticBlock, self).get_context(value)
渲染
^{pr2}$
Tags:
外部页面的上下文在块模板中可用,但不幸的是,
get_context
方法中不可用。(这是由于模板上下文的构建方式,get_context
的结果是merged into the parent context。)这是一个已知的限制:https://github.com/wagtail/wagtail/pull/2786#issuecomment-230416360https://github.com/wagtail/wagtail/issues/2824
一种可能的解决方法是重写
render
方法(这是公认的不理想的,因为您必须在那里重复部分或全部现有的render
逻辑)。在它现在正在工作(在
get_context
内)。如果有人对StreamField
有相同的问题,请确保将其呈现为:{% for block in page.body %} {% include_block block %} {% endfor %}
以下操作无效(空
parent_context
):{% include_block page.body %}
{{ page.body|safe }}
相关问题 更多 >
编程相关推荐