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

396
Visualizações
How to convert ' to quotes in javascript?

I am trying to pass a python list with string values from views.py to the template where a javascript uses the same for labels of a pie chart(plotly). The issue is when the list is received at the front-end, the list is getting the hexcode of the quote which is ' instead of the quotes. How to convert it to quote? Here is the snippet:

var trace1 = {
  x: {{labels}},
  y: {{values}},
  marker:{
    color: ['rgba(204,204,204,1)', 'rgba(222,45,38,0.8)', 'rgba(204,204,204,1)', ]
  },
  type: 'bar'
};

Now, i am getting the values for 'labels' as:

['One', 'Two', 'Three']

Instead of:

['One','Two','Three']

Just wanted to know are there any methods to avoid this easily instead of using string replace methods?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

For security reasons, Django escapes the quotes (and many other characters) when it renders the template.

If you're sure that this data is not harmful (i.e. is not entered by your site's users), then you can just use the the safe filter in the template:

{{ my_list | safe }}

The safe filter tells Django that the data is trustworthy, and, so it won't escape it.


Warning: Don't use safe filter if the data you're displaying on the templates is submitted by your site's users. That might lead to XSS attacks.

If you ever need to use safe with user-submitted data, you should first sanitize the data such as by using bleach or django-bleach.

about 4 years ago · Santiago Gelvez 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