在管理员上定制结构块模板的Wagtail

时间:2018-01-05 12:38:37

标签: django wagtail

我已阅读' custom-editing-interfaces-for-structblock'文档部分。然后我写了:

 settings = StructBlock([
            ('width', blocks.CharBlock(required=False, max_length=20 ) ),
            ('background_color', blocks.CharBlock(max_length=10, required=False))
        ],  form_template = 'personal_web/admin_blocks/section_settings.html' )

我已将wagtail / admin / templates / wagtailadmin / block_forms / struct.html中的代码复制到我的自定义结构模板中,以便更好地进行自定义。

---我的section_settings.html ---

<div class="{{ classname }}">
    {% if help_text %}
        <div class="object-help help">{{ help_text }}</div>
    {% endif %}

    <ul class="fields">
        {% for child in children.values %}
            <li{% if child.block.required %} class="required"{% endif %}>
                {% if child.block.label %}
                    <label{% if child.id_for_label %} for="{{ child.id_for_label }}"{% endif %}>{{ child.block.label }}:</label>
                {% endif %}
                {{ child.render_form }}
            </li>
        {% endfor %}
    </ul>
</div>

在管理员上有一个错误:

&#39; builtin_function_or_method&#39;对象不可迭代...在模板/Users/burakk/BurakWorks/Web/VIRTUAL_ENVIRONMENTS/python3.6.1_dj_1_11/lib/python3.6/site-packages/wagtail/wagtailadmin/templates/wagtailadmin/block_forms/sequence_member.html,错误在第23行

顺便说一句,我使用jinja作为模板渲染器,django 1.11.6,python 3.6

我查看这是否是一个jinja2问题我已经更改了children.values属性children.values()等...

现在在管理员上我看到所有元素为&#39; html string&#39;不是实际的输入字段......

由于

1 个答案:

答案 0 :(得分:1)

我认为这可能会发生,因为您的section_settings.html模板位于通常用于jinja2模板的位置内 - 可能是some_app/jinja2/personal_web/admin_blocks/section_settings.html(如果您使用http://docs.wagtail.io/en/v1.13.1/advanced_topics/jinja2.html中显示的配置) - 并最终被解释为Jinja2模板。以这种方式混合Jinja2和Django模板是未经测试的,并且可能以不可预测的方式失败(例如HTML被双重转义,正如您所见)。

尝试将其移至some_app/templates/personal_web/admin_blocks/section_settings.html,将模板更改回Django语法(children.values()更改回children.values等)。

相关问题