Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda