0

I am trying to create a javascript list from a python list using jinja2. My current implementation is this:

var go_words = [{{"\"" + user.names | join('\",\"') + "\""}}]

which yields:

var go_words = ['Name 1', ...]

For some reason the " character is not being interpreted correctly and thus my script is failing. Is there anyway to fix this? Note that my code for this javascript is in an html <script> tag which is included from another html template.

Even an inline list in the jinja brackets yields and incorrect list

var go_words = {{["test", "test1", "test2"]}}


var go_words = [&#39;test&#39;, &#39;test1&#39;, &#39;test2&#39;]
2
  • I don't have it right in front of me, but doesn't {{user.names}} do what you need? Commented Dec 22, 2018 at 2:22
  • @MarkMeyer it does remove the complexity I had for the join code above but it still formats the " incorrectly Commented Dec 22, 2018 at 2:28

1 Answer 1

1

You can use the safe filter to prevent Jinja from escaping templated values. For example:

var goWords = {{ user.names|safe }};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.