如何检查 Pelican 变量

How do I inspect Pelican variables

我正在修改 Pelican 模板,下面的代码会在每次找到页面时添加 url。我可以看到 p 对象具有属性 url 和 title.

然而我只知道这个是因为我从下面显示的另一个模板复制了代码。有什么方法可以检查 jinja2 或 Pelican 中的对象以了解其中包含的信息?

      {% for p in pages %}
        <h1 class = "sidebar-title">
          <a href="{{ SITEURL }}/{{ p.url }}">
          {{ p.title }}
          </a>
        </h1>

https://github.com/getpelican/pelican-themes/blob/master/backdrop/templates/base.html

<li{% if p == page %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ p.url }}">{{ p.title }}</a></li>

我不知道有官方资源详细解释所有变量、对象、属性和特性。

但作为开始,我认为以下起点就足够了:

  • Common variables available for the standard templates
  • pelican.contents.py: 这是包含(大部分)pelican 使用的数据结构的模块,这些数据结构在模板中可用。查看属性(@property,这些函数就像属性一样)和属性。在第 367ff 行有一些非常简单的子类定义可能有用。
  • pelican.writers.py: This module brings together the templating engine jinja2, the templates and the data to be inserted in the templates. Of special interest for you could be lines 138ff,因为这似乎是一个很好的点,可以简单地插入一些小的调试打印来查看数据结构中存在的真实数据。