Wagtail 在管理员上自定义结构块模板
Wagtail customizing struct block template on admin
我已阅读文档的 '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>
管理员出现错误:
'builtin_function_or_method' 对象不可迭代...在模板中 /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() 等...
现在在管理员上我看到的所有元素都是 'html string' 而不是实际的输入字段...
谢谢
我认为这可能会发生,因为您的 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
,等等)。
我已阅读文档的 '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>
管理员出现错误:
'builtin_function_or_method' 对象不可迭代...在模板中 /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() 等...
现在在管理员上我看到的所有元素都是 'html string' 而不是实际的输入字段...
谢谢
我认为这可能会发生,因为您的 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
,等等)。