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

187
Views
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 answers
Answer question

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