Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Want to pass json array as django variable inside javascript

I have a json array and I want to pass this inside a javascript variable, inside the django template. I am able to access the variable inside django template {{variable}} . But not able to access this inside the javascript.This is my variable:

[
    
    {'Book ID': '1', 'Book Name': 'Challenging Times',
    
     'Category': 'Business', 'Price': '125.60'},
    
    {'Book ID': '2', 'Book Name': 'Learning JavaScript',
    
     'Category': 'Programming', 'Price': '56.00'}
    
]

I have used {{variable|safe}} inside the js but not working. Plz let me know where I am making the mistake.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use the json_script template filter to add your variable to the template in a format that can be loaded in your JS

{{ variable|json_script:"foo" }}

<script>
    const foo = JSON.parse(document.getElementById('foo').textContent);
</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda