Django: Unable to use prefetch_related - python

What I want to do is that for a particular Cylinder Id , if cylinder is issued then the user name and the issue date will be displayed in cylinder List , like this
cylinderId | date | type | status |availability| issuedate | userName | returndate |
1 | 11/11| co2 | fill | available| 12/11(if exists)| xyz | 13/11(if exists)
so for that i used prefetch_related but it is not displaying anything in cylinder List:-
here is model:-
class Cylinder(models.Model):
stachoice=[
('Fill','fill'),
('Empty','empty')
]
substachoice=[
('Available','available'),
('Unavailable','unavailable'),
('Issued','issued')
]
cylinderId=models.CharField(max_length=50,primary_key=True,null=False)
gasName=models.CharField(max_length=200)
cylinderSize=models.CharField(max_length=30)
Status=models.CharField(max_length=40,choices=stachoice,default='fill')
Availability=models.CharField(max_length=40,choices=substachoice,default="Available")
EntryDate=models.DateTimeField(default=timezone.now)
def get_absolute_url(self):
return reverse('cylinderDetail',args=[(self.cylinderId)])
def __str__(self):
return str(self.cylinderId)
class Issue(models.Model):
cylinder=models.ForeignKey('Cylinder',on_delete=models.CASCADE)
userName=models.CharField(max_length=60,null=False)
issueDate=models.DateTimeField(default=timezone.now)
def save(self,*args,**kwargs):
if not self.pk:
if self.cylinder.Availability=='Available':
Cylinder.objects.filter(cylinderId=self.cylinder.cylinderId).update(Availability=('Issued'))
super().save(*args,**kwargs)
def __str__(self):
return str(self.userName)
here is cylinder list view:-
def cylinderListView(request):
cylinder=Cylinder.objects.all().prefetch_related('issue_set')
return render(request,'entry/cylinderList.html',locals())
here is cylinderList template:-
{% extends 'base.html'%}
{% block content %}
<div class="alldiv">
<h1 align="center">All Cylinder list</h1>
{% if cylinder %}
<div class='centerstage'>
<div class="post">
<table border="5" cellspacing="5" width="100%" >
<thead>
<tr bgcolor="#99c2ff"align="center">
<th height="50"
width="50">Cylinder Id</th>
<th height="50"
width="50">Date</th>
<th height="50"
width="50">Gas Name</th>
<th height="50"
width="50">Cylinder Size</th>
<th height="50"
width="50">Status</th>
<th height="50"
width="50">Availability</th>
<th height="50"
width="50">Issued Date</th>
<th height="50"
width="50">Customer</th>
<th height="50"
width="50">Return Date</th>
</thead>
<tbody>
{%for cy in cylinder%}
<tr bgcolor="#e6f0ff" align="center">
<td align="center" height="10"
width="50"><a href="{{cy.get_absolute_url}}">{{cy.cylinderId}}<a></td>
<td align="center" height="10"
width="50">{{cy.EntryDate}}</td>
<td align="center" height="10"
width="50">{{cy.gasName}}</td>
<td align="center" height="10"
width="50">
{{cy.cylinderSize}}</td>
<td align="center" height="10"
width="50">
{{cy.Status}}</td>
<td align="center" height="10"
width="50">{{cy.Availability}}</td>
<td align="center" height="10"
width="50">{{cy.issue.issueDate}}</td>
<td align="center" height="10"
width="50">{{cy.issue.userName}}</td>
</tr>
{% endfor %}
</tbody>
{% else %}
<div>
<h2>No record</h2>
</div>
</table>
</div>
</div>
</div>
{% endif %}
{% endblock %
}
I m unable to figure out that what i m missing , Is I m using prefetch_related?

You need to cycle through the issue_set like so:
{% for issue in cy.issue_set.all() %}
<td align="center" height="10" width="50">{{ issue.issueDate }}</td>
<td align="center" height="10" width="50">{{ issue.userName }}</td>
{% endfor %}

Related

Adding Data To Email Through Loop In Python

I am attempting to iterate through a map containing arrays to an HTML email template. I can print out the data in the array but, the data does not show up in the array after finishing the loop.
html_data = """
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<br>
<br>
Date: {{date}}
<br>
<br>
Hi,
<br>
<br>
Today's Picks Are in:
<br>
<br>
<div class="card-body">
<table class="table table-sm">
<thead>
<tr>
<th align='left'>Stock</th>
<th>Pick</th>
<th>Detail</th>
<th>Change</th>
</tr>
</thead>
<tbody>
<td align='left'>{{ picks }}</td>
{% for pick in picks %}
<tr>
<td align='center'> {{pick.stock}} </td>
# <td align='center'> {{pick.prices}} </td>
# <td align='center'>{{pick.option_details}}</td>
# <td align='center'>{{pick.change}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<br>
<br>
<p>If you would like to be removed from this list, please contact customer service: <mail_to="devs#hscottindustriescom">HScottIndustries</a> </p>
"""
Picks is the mapped array
picks = {
'stocks': stocks,
'prices': stock_price,
'option_details': options_details,
'change': change
}
The data from picks is added here.
msg = MIMEText(Environment().from_string(html_data).render(picks=picks, date=date_original), "html")
The output is this:
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<br>
<br>
Date: 07-05-2022
<br>
<br>
Hi,
<br>
<br>
Today's Picks Are in:
<br>
<br>
<div class="card-body">
<table class="table table-sm">
<thead>
<tr>
<th align='left'>Stock</th>
<th>Pick</th>
<th>Detail</th>
<th>Change</th>
</tr>
</thead>
<tbody>
<td align='left'>{'stocks': ['WPP', 'NEX', 'PTEN'], 'prices': ['45.21', '8.37', '13.39'], 'option_details': ['na', 'NEX Jul 15 2022 $7.50 Put', 'PTEN Jul 15 2022 $13.00 Put'], 'change': ['-10.19%', '-11.52%', '-11.53%']}</td>
<tr>
<td align='center'> </td>
# <td align='center'> </td>
# <td align='center'></td>
# <td align='center'></td>
</tr>
<tr>
<td align='center'> </td>
# <td align='center'> </td>
# <td align='center'></td>
# <td align='center'></td>
</tr>
<tr>
<td align='center'> </td>
# <td align='center'> </td>
# <td align='center'></td>
# <td align='center'></td>
</tr>
<tr>
<td align='center'> </td>
# <td align='center'> </td>
# <td align='center'></td>
# <td align='center'></td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
<p>If you would like to be removed from this list, please contact customer service: HScottIndustries </p>
<footer class="main-footer">
<strong>Copyright © 2022 <mail_to="devs#HScottIndustries.com">HScottIndustries LLC</a></strong>
How do I add the get the data to iterate correctly to the corresponding fields?
You are iterating over picks, which right now is a dictionary, meaning you will get dictionary keys in return. You can either format picks in a different way, or use an index. This format should work:
picks = [
{
'stocks': 'WPP',
'prices': '45.21',
'option_details': 'na',
'change': '-10.19%'
},
{
'stocks': 'NEX',
'prices': ...
},
...
]
Alternatively you can pass picks as zipped arrays in your view:
zipped_picks = zip(*picks.values())
Then access them with:
{% for pick in zipped_picks %}
<div> {{pick.0}} <div>
<div> {{pick.1}} <div>
<div> {{pick.2}} <div>
<div> {{pick.3}} <div>
{% endfor %}

I am trying to correctly make a block row within a table in a report

I'm trying to do a block tr inside an HTML table using the Python Jinja library for Front-end. The table appears to me with the following appearance:
El código HTML es el siguiente:
<body>
<div id="testName">
{{ ca['name'] }}
</div>
<br>
<div id="testDates">
Start test Date: <span>{{ ca['start_ca'] | time_str }}</span>
<br>
End test Date: <span>{{ ca['end_ca'] | time_str }}</span>
</div>
{% for stage in ca['stages'] %}
<table class="blueTable">
<tbody style="page-break-inside: auto;" >
<tr id="rowOne">
<th style="font-weight:bolder;">Stage</th>
<th colspan="5">Start Date</th>
<th colspan="5">End Date</th>
</tr>
<tr id="rowTwo">
<td >{{ stage.name }}</td>
<td colspan="5">{{stage.start | time_str}}</td>
<td colspan="5">{{stage.end | time_str}}</td>
</tr>
<tr style="background-color: #1C6EA4; color: white;">
<th>Step ID</th>
<th>Step</th>
<th>Start Date</th>
<th>End Date</th>
<th>Expected</th>
<th>Found</th>
<th>Not Found</th>
<th>Expected Ok</th>
<th>Ok</th>
<th>Fails</th>
<th>Overall</th>
</tr>
{%for step in stage.steps%}
<tr id="filaBucle">
<th rowspan='{{ step[1] | size }}'>
{{step[0]}}
</th>
{%for s in step[1]%}
<th >{{s.name}}</th>
<td>{{s.start | time_str}}</td>
<td>{{s.end | time_str}}</td>
<td style="color:darkblue;">{{s.expected}}</td>
<td style="color:green;">{{s.found}}</td>
<td style="color:red;">{{s.not_found}}</td>
<td style="color:darkblue;">{{s.expected_ok}}</td>
<td style="color:green;">{{s.ok}}</td>
<td style="color:red;">{{s.fails}}</td>
{% if s.overall < 50 %}
<td style="color: red;">{{s.overall}}%</td>
{% elif 50 <= s.overall < 100 %}
<td colspan="1" style="color: brown;">{{s.overall}}%</td>
{% else %}
<td style="color: green;">{{s.overall}}%<br></td>
{% endif %}
{% endfor %}
</tr>
{% if step[1] | has_errors %}
<tr style="color: #F3E9EB;background-color: #8E8585; border-style: hidden;">
<th colspan="11"> Errors Details</th>
</tr>
{%for s in step[1]%}
{% if s.error_detail %}
<tr style="color: #D22020; background-color: #D3C9C9;">
<th colspan="2">Step ID: {{s._id}}</th>
<th colspan="9"> {{s.name}}</th>
</tr>
{% for detail in s.error_detail %}
<tr style="color: #D22020; background-color: #D3C9C9;">
<td colspan="11"> {{detail | replace("\n", "<br>")}}</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</tbody>
</table>
{% endfor %}
I have tried to do everything possible with the CSS, but everything is out of place and I can't put those rows as subsections of the first column where it is numbered

HTML table to database

At this point, my table looks as follows:
<table border="0" cellpadding="0" cellspacing="0" class="ms-formtable" id="formTbl" style="margin-top: 8px;" width="100%">
<tbody>
<tr>
<td class="ms-formlabel" nowrap="true" valign="top" width="165px">
<h3 class="ms-standardheader">
<a name="SPBookmark_FileLeafRef">
</a>
Name
</h3>
</td>
<td class="ms-formbody" id="SPFieldFile" valign="top" width="450px">
<a href="http://google.com" onclick="DispDocItemEx(this, 'FALSE', 'FALSE', 'FALSE', '');">
X
</a>
</td>
</tr>
<tr>
<td class="ms-formlabel" nowrap="true" valign="top" width="165px">
<h3 class="ms-standardheader">
<a name="SPBookmark_Owner">
</a>
Name#
</h3>
</td>
<td class="ms-formbody" id="SPFieldChoice" valign="top" width="450px">
Z
</td>
</tr>
<tr>
<td class="ms-formlabel" nowrap="true" valign="top" width="165px">
<h3 class="ms-standardheader">
<a name="SPBookmark_DirectiveRank">
</a>
Age
</h3>
</td>
<td class="ms-formbody" id="SPFieldChoice" valign="top" width="450px">
52
</td>
</tr>
<tr>
<td class="ms-formlabel" nowrap="true" valign="top" width="165px">
<h3 class="ms-standardheader">
<a name="SPBookmark_Number">
</a>
number
</h3>
</td>
<td class="ms-formbody" id="SPFieldText" valign="top" width="450px">
1
</td>
</tr>
<tr>
<td class="ms-formlabel" nowrap="true" valign="top" width="165px">
<h3 class="ms-standardheader">
<a name="SPBookmark_Title">
</a>
Name of File
</h3>
</td>
<td class="ms-formbody" id="SPFieldText" valign="top" width="450px">
Funny Names
</td>
</tr>
<tr>
<td class="ms-formlabel" nowrap="true" valign="top" width="165px">
<h3 class="ms-standardheader">
<a name="SPBookmark_EffectiveFrom">
</a>
date
</h3>
</td>
<td class="ms-formbody" id="SPFieldDateTime" valign="top" width="450px">
1.1.2022
</td>
</tr>
</tbody>
</table>
I basically need to open an HTML file, filter table with id "formTbl" and then either create JSON with values : {Firsttd:Secondtd, "Name":"Test", "Date":"Blank"} or insert into database where First td (in tr tag we have 2 td, first it name of column and second is value) in table A and second td in table B. Is there any way? I´ve tried using Python, where I got so far json looks like [["","Name","","Test",""],["","Age","","12",""]] and in C# I´ve tried HTMLAgilityPack but it wasn´t working.
Here is the solution with JQuery.
<html>
<body>
<table id="example-table">
<tr>
<th>Name</th>
<th>Name#</th>
<th>Age</th>
<th>Number</th>
<th>Name of file</th>
<th>Date</th>
</tr>
<tr>
<td>X</td>
<td>Z</td>
<td>52</td>
<td>1</td>
<td>Name of file</td>
<td>2021-22-10</td>
</tr>
</table>
<textarea rows="10" cols="50" id="jsonTextArea">
</textarea>
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/table-to-json#1.0.0/lib/jquery.tabletojson.min.js"></script>
<script type="text/javascript">
var tableToJson = $('#example-table').tableToJSON();
var sendingData = JSON.stringify (tableToJson);
$('#jsonTextArea').val(sendingData);
// Send JSON data to backend
$.post('http://localhost/test.php', {sendingData}, function(data, textStatus, xhr) {
var backendResponse = data;
console.log(backendResponse);
});
</script>

Why request.form from input fields not work?

I have an HTML page with a form compiled yet with default values as a modify form, in python program i want to get the modified information, if there are. i have a ID to use for update the data in my DB with pymssql. When i get data from the form in HTML page, the ID it's get, but the CF block the program and give me the error: POST/[name_page] HTTP/1.1" 400
PYTHON
#app.route('/salva_modifiche_paziente',methods=['POST'])
def dati_paziente_modificato():
id = dett_id_paz()
cf = request.form.get['cf']
nome = request.form['nome']
cognome = request.form['cognome']
data_nascita = request.form['data_nascita']
residenza = request.form['residenza']
grado_dolore = request.form['grado_dolore']
sintomi = request.form['sintomi']
data_ricovero = request.form['data_ricovero']
data_dimissione = request.form['data_dimissione']
reparto = request.form['reparto']
n_stanza = request.form['n_stanza']
n_letto = request.form['n_letto']
modifica_paziente(id, cf, nome, cognome, data_nascita, residenza, grado_dolore, sintomi, data_ricovero,
data_dimissione, reparto, n_stanza, n_letto)
dett = dettagli_paziente_ricoverato()
return render_template('dettagli_paziente_ricoverato.html', det_paz=dett)
def modifica_paziente(id,cf,nome,cognome,data_nascita,residenza,grado_dolore,sintomi,data_ricovero,data_dimissione,reparto,n_stanza,n_letto):
connection1 = pymssql.connect(database="UNICLINIC")
connection2 = pymssql.connect(database="UNICLINIC")
cursor1 = connection1.cursor()
cursor2 = connection2.cursor()
cursor1.execute("UPDATE paziente SET CF = (%s), nome = (%s), cognome = (&s), \
data_di_nascita = (%s), residenza = (%s), grado_dolore = (%d), sintomi = (%s) WHERE ID_paziente = %d",(cf,nome,cognome,data_nascita,residenza,grado_dolore,sintomi, int(id) ))
cursor2.execute("UPDATE ricoverato SET data_ricovero = (6s), \
data_dimissione = (%s), COD_reparto = (%s), n_stanza = (%s), n_letto = (%s) \
WHERE ID_paziente = (%d)"
,(data_ricovero, data_dimissione, reparto, n_stanza, n_letto,int(id)))
connection1.commit()
connection2.commit()
cursor1.close()
cursor2.close()
connection1.close()
connection2.close()
def dett_id_paz():
id = request.form['id_paziente']
print(id)
return id
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Modifica paziente | UNICLINIC</title>
<link rel="stylesheet" href={{ url_for('static', filename='style.css') }} type="text/css" media="all"/>
</head>
<body>
<div>
<table class="head_banner">
<tr>
<td><img id="logo" src={{ url_for('static', filename='immagini/logo_uniclinic.png') }} alt="Logo UNICLINIC"/></td>
<td class="menu"><button class="menu_btn">HOME</button></td>
<td class="menu"><button class="menu_btn">LOGIN</button></td>
<td class="menu"><button class="menu_btn">CONTACTS</button></td>
</tr>
</table>
<table class="tab_hd">
<thead>
<th>
<td colspan="2" id="p_tit">Dati profilo di {{det_paz.nome}} {{det_paz.cognome}}<td>
</th>
</thead>
</table>
<table class="tab_profilo">
<form id="modifica" method="post" action="salva_modifiche_paziente" class="form">
<tr>
<td class="p_dn">ID paziente:</td>
<td class="p_dv">
{{det_paz.id}}
<input style="display:none" id="id_paziente" name="id_paziente" type="text" value="{{det_paz.id}}" />
</td>
</tr>
<tr>
<td class="p_dn">Codice Fiscale:</td>
<td class="p_dv">
<input type="text" id="cf" name="cf " value="{{det_paz.cf}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Nome:</td>
<td class="p_dv">
<input type="text" id="nome" name="nome" value="{{det_paz.nome}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Cognome:</td>
<td class="p_dv">
<input type="text" id="cognome" name="cognome" value="{{det_paz.cognome}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Data di nascita:</td>
<td class="p_dv">
<input type="date" id="data_nascita" name="data_nascita" value="{{det_paz.data_nascita}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Residenza:</td>
<td class="p_dv">
<input type="text" id="residenza" name="residenza" value="{{det_paz.residenza}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Grado dolore:</td>
<td class="p_dv">
<select name="grado_dolore" id="grd_d">
{% for g in range(10) %}
<option type="text" id="grado_dolore" name="grado_dolore" value="{{g+1}}">Grado {{g+1}}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td class="p_dn">Sintomi:</td>
<td class="p_dv">
<input type="text" id="sintmi" name="sintomi" value="{{det_paz.sintomi}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Data ricovero:</td>
<td class="p_dv">
<input type="date" id="data_ricovero" name="data_ricovero" value="{{det_paz.data_ricovero}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Data dimissione:</td>
<td class="p_dv">
<input type="date" id="data_dimissione" name="data_dimissione" value="{{det_paz.data_dimissione}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Reparto ricovero:</td>
<td class="p_dv">
<label for="reparto"></label>
<select name="reparto" id="rep" class="p_dv">
{% for reparto in rep %}
<option type="text" id="reparto" name="reparto" value="{{reparto.COD_reparto}}">{{reparto.COD_reparto}} - {{reparto.nome_reparto}}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td class="p_dn">Stanza nr.:</td>
<td class="p_dv">
<input type="text" id="n_stanza" name="n_stanza" value="{{det_paz.n_stanza}}"/>
</td>
</tr>
<tr>
<td class="p_dn">Letto nr.:</td>
<td class="p_dv">
<input type="text" id="n_letto" name="n_letto" value="{{det_paz.n_letto}}"/>
</td>
</tr>
<tr class="r_bd">
<td class="b_dn"><button type="submit" form="modifica" class="menu_btn_d">CONFERMA</button></td>
<td class="b_dn"><button type="reset" class="menu_btn_d">ANNULLA</button></td>
</tr>
</form>
</table>
</div>
</body>
</html>

How do I parse through this json data in a more efficient way with Python?

How do I parse through this json data in a more efficient way. I'd like to do it with a for loop so the code doesn't repeat itself.
Here's the data endpoint: https://api.coingecko.com/api/v3/exchange_rates
and the json response sample:
{
"rates": {
"btc": {
"name": "Bitcoin",
"unit": "BTC",
"value": 1,
"type": "crypto"
},
"eth": {
"name": "Ether",
"unit": "ETH",
"value": 48.316,
"type": "crypto"
},
"ltc": {
"name": "Litecoin",
"unit": "LTC",
"value": 169.967,
"type": "crypto"
}
my view.py code:
def btc_to_currency(request):
exchange_endpoint = "https://api.coingecko.com/api/v3/exchange_rates"
request_exchange_data = requests.get(exchange_endpoint)
results_exchange_data = request_exchange_data.json()
data_exchange = results_exchange_data["rates"]
#print(data_exchange)
btc = (data_exchange['btc'])
xrp = (data_exchange['xrp'])
xau = (data_exchange['xau'])
xag = (data_exchange['xag'])
return render(request, 'crypto/btc_to_currency.html', {'btc' : btc, 'xrp': xrp, 'xau': xau, 'xag': xag})
and my template html code:
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
<thead>
<tr>
<th rowspan="2" class="is-size-7 has-text-centered">Name</th>
<th rowspan="2" class="is-size-7 has-text-centered">Unit</th>
<th rowspan="2" class="is-size-7 has-text-centered">Value</th>
<th rowspan="2" class="is-size-7 has-text-centered">Type</th>
</tr>
</thead>
{% load humanize %}
<tbody>
<tr>
<th class="is-size-7 has-text-centered"><strong>{{ btc.name }}</strong></th>
<td class="has-text-centered">{{ btc.unit }}</td>
<td class="has-text-centered">{{ btc.value }}</td>
<td class="has-text-centered">{{ btc.type }}</td>
</tr>
<tr>
<th class="is-size-7 has-text-centered"><strong>{{ xrp.name }}</strong></th>
<td class="has-text-centered">{{ xrp.unit }}</td>
<td class="has-text-centered">{{ xrp.value|intcomma }}</td>
<td class="has-text-centered">{{ xrp.type }}</td>
</tr>
<tr>
<th class="is-size-7 has-text-centered"><strong>{{ xau.name }}</strong></th>
<td class="has-text-centered">{{ xau.unit }}</td>
<td class="has-text-centered">{{ xau.value }}</td>
<td class="has-text-centered">{{ xau.type }}</td>
</tr>
<tr>
<th class="is-size-7 has-text-centered"><strong>{{ xag.name }}</strong></th>
<td class="has-text-centered">{{ xag.unit }}</td>
<td class="has-text-centered">{{ xag.value }}</td>
<td class="has-text-centered">{{ xag.type }}</td>
</tr>
</tbody>
</table>
I've been able to parse other json data using a forloop, but the structure was different. it was a list of dictionaries like this below:
[
{
"id": "bitcoin",
"symbol": "btc",
"name": "Bitcoin",
"image": "https://assets.coingecko.com/coins/images/1/large/bitcoin.png?1547033579",
"current_price": 6915.62
}
]
for that I used:
def latest(request):
per_page_limit = int(request.GET.get('limit', 10))
coin_list_url = f"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page={per_page_limit}&page=1&sparkline=false"
request_coin_list = requests.get(coin_list_url)
results_coin_list = request_coin_list.json()
crypto_data_geckco = []
for currency_gecko in results_coin_list:
crypto_data_geckco.append(currency_gecko)
return render(request, 'crypto/latest.html', { 'crypto_data_geckco': crypto_data_geckco} )
and then in the template:
{% for currency in crypto_data_geckco %}
<div class="box">
<article class="media">
<div class="media-left is-size-4">
<figure class="image is-96x96">
<img src="{{ currency.image }}" alt="Crypto Image Logo">
</figure>
<br>
<br>
<small><strong>{{ currency.name }} ({{ currency.symbol|upper }})</strong></small>
<br>
<span class="tag is-dark is-medium"><small><strong>Rank: #{{ currency.market_cap_rank }}</strong></small></span>
</div>
{% load humanize %}
{% load mathfilters %}
<div class="media-content">
<div class="content media-right is-size-6">
<br>
<strong>{{ currency.name }} ${{ currency.current_price }}</strong>
<br>
<strong>Market Cap:</strong> {{ currency.market_cap|intword }}
<br>
<hr>
<strong>24h Low / 24h High:</strong> ${{ currency.low_24h }} / ${{ currency.high_24h }}
<br>
<strong>24h Price Change:</strong> ${{ currency.price_change_24h }}
<br>
<strong>24h Price Change (%):</strong> {{ currency.price_change_percentage_24h|floatformat:2|intcomma }}%
<br>
<hr>
<strong>Trading Volume (24hr):</strong> ${{ currency.total_volume|intword }}
<br>
<strong>Volume / Market Cap:</strong> {{ currency.total_volume|div:currency.market_cap|floatformat:3|intcomma }}
<br>
That worked fine.
thanks
#ThierryLathuille comment was correct and solved the issue.
Then in the html template I was able to access the data with a for loop:
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
<thead>
<tr>
<th rowspan="2" class="is-size-7 has-text-centered">Name</th>
<th rowspan="2" class="is-size-7 has-text-centered">Unit</th>
<th rowspan="2" class="is-size-7 has-text-centered">Value in BTC</th>
<th rowspan="2" class="is-size-7 has-text-centered">Type</th>
</tr>
</thead>
{% for exchange in data_exchange.values %}
{% load humanize %}
<tbody>
<tr>
<th class="is-size-7 has-text-centered"><strong>{{ exchange.name }}</strong></th>
<td class="has-text-centered">{{ exchange.unit }}</td>
<td class="has-text-centered">{{ exchange.value|intword|intcomma }}</td>
<td class="has-text-centered">{{ exchange.type }}</td>
</tr>
{% endfor %}
</tbody>
</table>

Categories