0

I am testing the api from block.io https://block.io/api/simple/python

{
  "status" : "success",
  "data" : {
    "network" : "BTCTEST",
    "available_balance" : "0.0",
    "pending_received_balance" : "0.0",
    "balances" : [
      {
        "user_id" : 0,
        "label" : "default",
        "address" : "2NCjjB8iVKu9jnYpNcYKxxRYP9w6eWXZAq4",
        "available_balance" : "0.00000000",
        "pending_received_balance" : "0.00000000"
      }
    ]
  }
}

I would like to display for example only the wallet address of the user in question so that he can make a deposit.

My views.py

from django.shortcuts import render
from block_io import BlockIo
version = 2 # API version
block_io = BlockIo('28a8-ba34-8b81-137d', '1111111', version)

def index(request):
    balance = block_io.get_address_balance(labels='shibe1')
    context = {'balance': balance}
    return render(request, 'home.html', context)

home.html

<h1>Block.io API</h1>
{{ balance }}

<h1>I want display example this data</h1>
<h1>Label: default</h1>
<h1>Available balance: 0.00000000</h1>
<h1>Pending received balance: 0.00000000</h1>
<h1>Address: 2NCjjB8iVKu9jnYpNcYKxxRYP9w6eWXZAq4</h1>

When I do this all the data is displayed but example I only want to address

Image displayed data

{'status': 'success', 'data': {'network': 'BTCTEST', 'available_balance': '0.0', 'pending_received_balance': '0.0', 'balances': [{'user_id': 1, 'label': 'shibe1', 'address': '2NADUMWksxJZRKPSNXya8R2LYQY2fGa5mNY', 'available_balance': '0.00000000', 'pending_received_balance': '0.00000000'}]}} 

How can I refer only to the data that I want?

2 Answers 2

1

You can perform all sorts of lookups on variables in Django Template language using just the . operator. Also your data has a list so you would need to loop over it:

<h1>Block.io API</h1>
<h1>I want display example this data</h1>
{% for bal in balance.data.balances %}
    <h1>Label: {{ bal.label }}</h1>
    <h1>Available balance: {{ bal.available_balance }}</h1>
    <h1>Pending received balance: {{ bal.pending_received_balance }}</h1>
    <h1>Address: {{ bal.address }}</h1>
{% endfor %}
Sign up to request clarification or add additional context in comments.

1 Comment

@Abdul Aziz Barkat Thanks for your advice.
0

Please refer to below file changes :

My views.py

from django.shortcuts import render
from block_io import BlockIo
version = 2 # API version
block_io = BlockIo('28a8-ba34-8b81-137d', '1111111', version)

def index(request):
    balance = block_io.get_address_balance(labels='shibe1')
    context = {'all_balance': balance['data']['balances']}
    return render(request, 'home.html', context)

home.html

<h1>Block.io API</h1> 

{% for balance in all_balance %}
    <h1>Label: {{ balance.label }}</h1>
    <h1>Available balance: {{ balance.available_balance }}</h1>
    <h1>Pending received balance: {{ balance.pending_received_balance }}</h1>
    <h1>Address: {{ balance.address }}</h1>
{% endfor %}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.