Вот мой небольшой скрипт на Python:
Код: Выделить всё
path = Path(__file__).parent
env = Environment(
loader=FileSystemLoader(path / "templates")
)
template = env.get_template("template1.rst")
rendered = template.render(sample={"a": {"b": "c"}})
Код: Выделить всё
.. toctree::
:maxdepth: 3
{% for k, v in sample.items() recursive %}
- {{ k }}:
{%- if v is string %}
{{ v }}
{%- else %}
{{ loop(v) }}
{%- endif -%}
{%endfor%}
Код: Выделить всё
File "/home/jaja/Bureau/coding/bac_a_sable/sphinx_test/templates/template1.rst", line 5, in top-level template code
{% for k, v in sample.items() recursive %}
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jaja/Bureau/coding/bac_a_sable/sphinx_test/templates/template1.rst", line 21, in template
{{ loop(v) }}
^^^^^^^^^^^^^^^^^^
File "/home/jaja/Bureau/coding/bac_a_sable/sphinx_test/templates/template1.rst", line 5, in template
{% for k, v in sample.items() recursive %}
^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)
Не может ли Jinja выполнить рекурсивный цикл? словари?
Подробнее здесь: https://stackoverflow.com/questions/791 ... esnt-works
Мобильная версия