Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
Fix @ Jinja variable parsing at Javascript code in a static JS file …?

I am running into this “old problem”: Jinja variable parsing only works on the html template (passed in to render_template), so if your Javascript code is in a static JS file the Flask/Jinja variables can't be accessed”. Jinja Flask issue: Uncaught SyntaxError: Unexpected token { in JSON at position 1 at JSON.parse Does anyone know if there is already a solution for this. It's ugly to embed the JS code in the HTML file

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the tojson Jinja filter to safely embed only the JSON data into the document, then load it in JS.

{% set data = [1, 2, 3, 4] %}
<script id="data" type="application/json">{{ data|tojson }}</script>

And in the external JS file:

const value = JSON.parse(document.getElementById('data').textContent);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!