0

正如建议的那样,我想在 .html 文件中编写 hogan.js 代码,该文件位于烧瓶结构的模板文件夹中。当我执行 python 文件时,索引页面呈现波纹管错误

jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError: unexpected char u'#' at 36667

我还附上了下面的 index.html 代码的一部分。

<div class="cell link">
    <a href="{{url}}"> >> view {{type}} details</a>
    {{#console_id}}
    <a href="/project/instances/{{console_id}}/vnc" class="vnc_window">» open console</a>
    {{/console_id}}
</div>

python文件代码

@app.route('/')
def index():
    return render_template('index.html')

我还包括了 hogan.js 文件

<script src="{{ url_for('static', filename='horizon/lib/hogan-2.0.0.js') }}" type="text/javascript"></script>

请帮我找出这个错误。

4

1 回答 1

1

您可以尝试像这样转义 hogan 标签:

{{ '{{#console_id}}' }}

否则,flask 会将其视为 jinja 模板的一部分,并尝试评估花括号内的表达式。

如果你想避免自动转义,你可以使用safe过滤器。

 {{ '{{> table1}}' | safe }}
于 2013-09-19T08:00:29.870 回答