templatetags和context ['request']

时间:2017-11-04 00:11:40

标签: wagtail

所以我正在学习Wagtail,并试图了解如何生成菜单。到目前为止,我发现bakerydemo repo很有帮助。对我来说,一个主要的困惑点是理解如何使用面包店演示中用于菜单的模板标签。下面是get_site_root标记的代码(django docs recommend that as of 1.11 that simple_tag will also work,因此我将其更改为。)

@register.assignment_tag(takes_context=True)
  def get_site_root(context):
   # This returns a core.Page. The main menu needs to have 
   # the site.root_page
   #defined else will return an object attribute error ('str' object 
   #has no attribute 'get_children')
   return context['request'].site.root_page

无论我做什么,我似乎无法让它发挥作用。要么没有返回任何内容,要么我得到各种错误,例如请求密钥不在上下文或其他内容中。我查看了Site middleware,然后将其跟踪到网站模型staticmethod“find_for_request”,后者又应该调用"get_site_for_hostname" in the sites.py。无论如何,我会喜欢一些关于我做错或误解的指导。此外,欢迎使用任何帮助来理解从页面层次结构生成菜单的“wagtailthonic”方式。

这是页面和网站表的图像。

wagtail site and page tables

0 个答案:

没有答案
相关问题