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

189
Vistas
Why are script tags auto converting & to &?

I'm experiencing a strange problem I haven't run into before. My html is generated via Django templates, and consist of some basic code that initializes a DataTable based on a query string with some GET variables (i.e. "/report1/?filter1=abc&filter2=def").

However, all of a sudden, whenever I write the Django template variable out within a <script></script> tag the & is converted to &amp;, like this:

<script>
var link = "/report1/?filter1=abc&amp;filter2=def"
</script>

However, when not inside a script tag, the string outputs as originally intended: "/report1/?filter1=abc&filter2=def"

This is based off the exact same Django template variable with no changes.

What about the script is causing the & to be encoded? This happens in current versions of Edge and Firefox. Django clearly doesn't know anything about the <script></script> tags so it must be a browser thing.

Any ideas how to prevent this from happening? It is something that didn't seem to happen in the past.

Thanks!

For reference, my Django template looks something like this:

{{ string }}<br>
<script>
var link = "{{ string }}"
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Okay, so my mess up, when I updated to the latest versions, I neglected to realized that strings needed to be marked with |safe now

Of course I realized this only after writing out this post.

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