I am making a api call in my django app. The response is json. Currently I am looping through the data in my template and showing all the data in a table.
All the data shows in the table except for the image_url. The image_url has a url path to a jpg. Do this type of json need to be handled differently than a normal string?
I notice there are a few fields missing data and I cannot figure out why these few fields are missing the data and fields before them and after them are working fine.
This is one of the json objects
[
{
"name": "_____",
"id": "_____",
"url": "https://api.deckbrew.com/mtg/cards/_____",
"store_url": "http://store.tcgplayer.com/magic/unhinged/_____?partner=DECKBREW",
"types": [
"creature"
],
"subtypes": [
"shapeshifter"
],
"colors": [
"blue"
],
"cmc": 2,
"cost": "{1}{U}",
"text": "{1}: This card's name becomes the name of your choice. Play this ability anywhere, anytime.",
"power": "1",
"toughness": "1",
"formats": {},
"editions": [
{
"set": "Unhinged",
"set_id": "UNH",
"rarity": "uncommon",
"artist": "Ron Spears",
"multiverse_id": 74252,
"flavor": "{1}: This card's flavor text becomes the flavor text of your choice. (This ability doesn't work because it's flavor text, not rules text (but neither does this reminder text, so you figure it out).)",
"number": "23",
"layout": "normal",
"price": {
"low": 0,
"median": 0,
"high": 0
},
"url": "https://api.deckbrew.com/mtg/cards?multiverseid=74252",
"image_url": "https://image.deckbrew.com/mtg/multiverseid/74252.jpg",
"set_url": "https://api.deckbrew.com/mtg/sets/UNH",
"store_url": "http://store.tcgplayer.com/magic/unhinged/_____?partner=DECKBREW"
}
]
},
This is how I am handling the data in the view
def graphs(request):
if request.user.is_authenticated():
data = []
r = requests.get('https://api.deckbrew.com/mtg/cards')
jsonList = r.json()
for cards in jsonList:
data.append(cards)
return render(request, 'graphs/graphs.html', {'data': data})
else:
return redirect('index')
This is how I am accessing the data in the template I marked the ones which are missing.
{% for card in data %}
<tr>
<td>{{ card.name }}</td>
<td>{{ card.id }}</td>
<td>{{ card.url }}</td>
<td>{{ card.store_url }}</td>
<td>{{ card.types }}</td>
<td>{{ card.subtypes }}</td>
<td>{{ card.colors }}</td>
<td>{{ card.cmc }}</td>
<td>{{ card.cost }}</td>
<td>{{ card.text }}</td>
<td>{{ card.power }}</td>
<td>{{ card.toughness }}</td>
<td>{{ card.formats }}</td>
<td>{{ card.editions }}</td>
<td>{{ card.set }}</td> # MISSING
<td>{{ card.set_id }}</td> # MISSING
<td>{{ card.rarity }}</td> # MISSING
<td>{{ card.artist }}</td> # MISSING
<td>{{ card.multiverse_id
<td>{{ card.flavor }}</td> # MISSING
<td>{{ card.number }}</td> # MISSING
<td>{{ card.layout }}</td> # MISSING
<td>{{ card.price }}</td> # MISSING
<td>{{ card.low }}</td> # MISSING
<td>{{ card.median }}</td> # MISSING
<td>{{ card.high }}</td> # MISSING
<td>{{ card.url }}</td>
<td>{{ card.image_url }}</td> # MISSING
<td>{{ card.set_url }}</td> # MISSING
<td>{{ card.store_url }}</td>
</tr>
{% endfor %}
