Jaydipsinh
Jaydipsinh

Reputation: 491

how to integrate hogan.js code inside flask template?

As suggested i m tring to write hogan.js code inside .html file which located in templates folder of flask structure. when i execute python file, index page render with bellow error

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

i have also attached part of index.html code bellow.

<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 file code

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

i also included hogan.js file

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

please help me to figure out this error.

Upvotes: 0

Views: 321

Answers (1)

zero323
zero323

Reputation: 330173

You can try escaping hogan tags like this:

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

Otherwise flask treats it as a part of jinja template and tries to evaluate expression inside curly braces.

If you want to avoid autoescaping you can use safe filter.

 {{ '{{> table1}}' | safe }}

Upvotes: 1

Related Questions