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

153
Visualizações
API returning an array inside of an object how to display contents- Django

So I am requesting spot price from cex API, it returns something like this {"data":[{"amount: "67000.0", "base": "BTC", "currency": "USD"}]} of course there is more than one returned so I want to loop over it.

In my views.py I am passing it into my context 'price': price. Then inside of my .html file I have a list with a for loop for example:

<ul>
  {% for x in price %}
    <li>{{ x }}</li>
  {% endfor %}
</ul>

Then when I open my .html page I get

  • data
  • But what I'd like to be able to do is make a table where I have three columns to show the amount, base and currency. I am unsure on how to extract this data individualy?

    over 4 years ago · Santiago Trujillo
    2 Respostas
    Responde à pergunta

    0

    You can enumerate over the .values of price, and then enumerate over the dictionaries in that list with:

    <table>
    {% for vs in price.values %}
        {% for v in vs %}
            <tr><td>{{ v.amount }}</td><td>{{ v.base }}</td><td>{{ v.currency }}</td></tr>
        {% endfor %}
    {% endfor %}
    </table>
    over 4 years ago · Santiago Trujillo Relatório

    0

    In Django templates, you can access to dictionary items with a expresión like {{ dictionary.key }}

    
    <ul>
      {% for x in price %}
        <li>{{ x.amount }}</li>
      {% endfor %}
    </ul>
    

    See the docs on https://docs.djangoproject.com/en/3.2/ref/templates/api/#variables-and-lookups

    over 4 years ago · Santiago Trujillo 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