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

398
Vistas
How to render python dictionary values in Javascript Fetch API (forEach)?

I am trying to render python dictionary values inside a Javascript Fetch API. I tried various ways to do so such as serializing values and using dictionary keys to access the dictionary values. I got no error message but the values I rendered are all "undefined" on my webpage.

Python

def portfolio_position(request):
positions = Portfolio.objects.filter(owner=request.user, off_portfolio=False).order_by('-symbol').values()
return JsonResponse([position for position in positions], safe=False)

Javascript

function load_portfolio_position() {
  fetch('/portfolio_position')
  .then(response => response.json())
  .then(positions => {
      console.log(positions);
      var table = document.getElementById("portfolio-table");
      positions.forEach(position => {
        var row = table.insertRow(1);
        row.id = `row_${position.symbol}`;
        var symbol = row.insertCell(0);
        var price = row.insertCell(1);
        var change = row.insertCell(2);
        var average_cost = row.insertCell(3);
        var position = row.insertCell(4);
        var pnl = row.insertCell(5);
        var pnl_percent = row.insertCell(6);
        symbol.innerHTML = `${position.symbol}`; 
        price.innerHTML = `${position.price}`; 
        change.innerHTML = `${position.change}`; 
        var avc = parseFloat(position.cost).toFixed(3);
        average_cost.innerHTML = `${avc}`; 
        position.innerHTML = `${position.position}`;
        pnl.innerHTML = `${position.pnl}`;
        pnl_percent.innerHTML = `${position.pnl_percent}`;
      });
  })
}

This is the dictionary with values from console log

This is the undefined result I got in my webpage

Appreciate your help!

about 4 years ago · Juan Pablo Isaza
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