我试图自定义基于this tutorial的表单模板。据我所知,render()
只是给标签添加一些属性。例如,我添加placeholder = "abc"
,它运作良好。jinja2表单渲染不允许包含“ - ”的属性
{% call inserttourbus(id = "formAddNewRow") %}
<div class="fieldWrapper">
{% if inserttourbus['bustype'].label() %}Bus Type{% endif %}
{{ inserttourbus['bustype'].render(placeholder="abc")|safe }}
{% if inserttourbus['bustype'].errors() %}Not filled yet!{% endif %}
</div>
{% endcall %}
这里是我的问题: - 我用bootstrap typeahead
我的模板,所以我需要将以下属性添加到inserttourbus
文本
data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska"]'
因此,这将成为
{{ inserttourbus['bustype'].render(placeholder="abc", data-provide="typeahead", data-items="4", data-source='["Alabama","Alaska"]')|safe }}
但是jinja2引擎似乎不接受data-provide
,data-items
,等等,因为它包含"-"
个字符。如果我将data-provide
更改为dataprovide
,则jinja2引擎可以很好地呈现代码。
但是,在bootstrap typeahead
javascript中,所有变量定义为data-provide
,data-items
。如果我将它们更改为dataprovide
,dataitems
,则javascipt停止工作。
请给我一个解决方案: - 如何使接受的Jinja2具有属性“ - ” - 其他的解决方案,建议
thanks。无论如何添加数据提供render()? – John
也许你可以插入一个unicode破折号:''N {HYPHEN-MINUS}' – voscausa
我改变数据提供给数据u'\ N {HYPHEN-MINUS}'提供,但它不起作用 – John