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

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

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 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