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

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