Issue
This is my code, who calls error:
{% extends "add_book_header.html" %}
{% block content %}
{% if books %}
<p>Results: {{ books|length }}</p>
{% for book in books %}
<div class="card h-100">
<img src={{book["volumeInfo"]["imageLinks"]["smallThumbnail"]}} class="card-img-top">
<div class="card-body">
<h5 class="card-title">{{ book["volumeInfo"]["title"]}}</h5>
<p class="card-text">descripthion</p>
<a href="#" class="btn btn-primary">link</a>
</div>
</div>
{% endfor %}
{% endif %}
{% endblock %}
and this is structure of book
{
"kind": "books#volume",
"id": "NwxaDwAAQBAJ",
"etag": "guYzwBLXoHI",
"selfLink": "https://www.googleapis.com/books/v1/volumes/NwxaDwAAQBAJ",
"volumeInfo": {
"title": "Цельная жизнь. Главные навыки для достижения ваших целей",
"authors": [
"Джек Кэнфилд",
"Марк Виктор Хансен",
"Лес Хьюитт"
],
"publisher": "Litres",
"publishedDate": "2020-01-31",
"description": "Основная причина, по которой у большинства из нас не ладятся дела, – расфокусированность. Мы отвлекаемся от выбранного курса, откладываем важное на потом и в итоге под разными предлогами отказываемся от достижения цели. Авторы «Цельной жизни» предлагают 10 ключевых стратегий, которые помогут сосредоточиться на главном и добиться своего. Эта книга, проданная общим тиражом 600 000 экземпляров, выдержала десять переизданий на английском языке и сейчас переживает второе рождение на русском. Ранее она выходила в сокращенной и заметно переработанной версии. Новый вариант максимально приближен к оригиналу. Он дополнен вдохновляющими историями и техниками, не вошедшими в предыдущее издание.",
"industryIdentifiers": [
{
"type": "ISBN_10",
"identifier": "5041133891",
},
{
"type": "ISBN_13",
"identifier": "9785041133894",
}
],
"readingModes": {
"text": true,
"image": true,
},
"pageCount": 505,
"printedPageCount": 505,
"printType"
"categories": [
"Psychology / Education & Training",
"Psychology / General"
],
"averageRating": 5.0,
"ratingsCount": 1,
"maturityRating": "NOT_MATURE",
"allowAnonLogging": true,
"contentVersion": "1.3.3.0.preview.3",
"panelizationSummary": {
"containsEpubBubbles": false,
"containsImageBubbles": false,
},
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?id=NwxaDwAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&imgtk=AFLRE71lKFAeu_Yn1NL-co5ed48HedO9HKLjSDYj5gwf_QXOxKOLmwtML58eByCk-KumaPbqi-mPCm2Hvabhyrqc0k2s_m7PlyLgMYTEiph1MCTSO7h7FqS0au_KU3uAQeVAGmWdx_Qm&source=gbs_api",
"thumbnail": "http://books.google.com/books/content?id=NwxaDwAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&imgtk=AFLRE73fv48xV0IazZs8xkdh4eWP4wIUmPjAze160rGEe2Djr5QGlUtqsQdLe6rYvlavPDrzy8N2x53TImANJyv-rF6vztH1HN82c8kpUr090UPlncObSAUL0_g-mrY02jvUF2VHv_LS&source=gbs_api",
"small": "http://books.google.com/books/content?id=NwxaDwAAQBAJ&printsec=frontcover&img=1&zoom=2&edge=curl&imgtk=AFLRE71W89k5GICHa60oHUhVkFn2TQb0mf2BT8sV4UJE4rQEHPrg8gi7ocADy2d17h1hzVttahG5_dZebwBMYky9sM5LGXZk5pFsR3an20nZqyL5qFx9tMe2IjYdiZA51nRxP9qErsgp&source=gbs_api",
"medium": "http://books.google.com/books/content?id=NwxaDwAAQBAJ&printsec=frontcover&img=1&zoom=3&edge=curl&imgtk=AFLRE72KZCR3kxHuC7Wwv7dfjJYNcgSoep9eXMRzRTPPPdspCUrX7d9ySFWxLDnBoxT8mZPQfjPwiZbepP2ms8J5bKam3aYOfxwnvW3ngqlMIYGYciXeizspZIvhEdfqGrUFTPXuvxhV&source=gbs_api",
"large": "http://books.google.com/books/content?id=NwxaDwAAQBAJ&printsec=frontcover&img=1&zoom=4&edge=curl&imgtk=AFLRE70VGEvMyFnUkpl-uvwjWHDLZtKXoN766b0Ue5vB48hug5kPIzGvVmrrhxKbShuRLT2gQo3ZB_jiuN3ENFBOXDDXllsWG2p4TGVF9nEax1sEgpTxG8HWqeHi15lVvYTPrqU7RRBv&source=gbs_api",
"extraLarge": "http://books.google.com/books/content?id=NwxaDwAAQBAJ&printsec=frontcover&img=1&zoom=6&edge=curl&imgtk=AFLRE71SsWc6rXWi-38mNgkbJI36hzGlHxqvQBJBQQPQsCg9iFX7g-lOpTk4NZNqjxPwtdSApWp8unszC5R5hhbHKWDbLkewsXEPpWPLLZmka8RVv3_HPBWANHDASHyiYjKRfeyFV59i&source=gbs_api",
},
"language": "ru",
"previewLink": "http://books.google.ru/books?id=NwxaDwAAQBAJ&hl=&source=gbs_api",
"infoLink": "https://play.google.com/store/books/details?id=NwxaDwAAQBAJ&source=gbs_api",
"canonicalVolumeLink": "https://play.google.com/store/books/details?id=NwxaDwAAQBAJ",
},
"layerInfo": {
"layers": [
{
"layerId": "geo",
"volumeAnnotationsVersion": "5",
}
],
},
"saleInfo": {
"country": "RU",
"saleability": "NOT_FOR_SALE",
"isEbook": false,
},
"accessInfo": {
"country": "RU",
"viewability": "PARTIAL",
"embeddable": true,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": true,
"acsTokenLink": "http://books.google.ru/books/download/%D0%A6%D0%B5%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F_%D0%B6%D0%B8%D0%B7%D0%BD%D1%8C_%D0%93%D0%BB%D0%B0%D0%B2%D0%BD%D1%8B%D0%B5-sample-epub.acsm?id=NwxaDwAAQBAJ&format=epub&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api",
},
"pdf": {
"isAvailable": true,
"acsTokenLink": "http://books.google.ru/books/download/%D0%A6%D0%B5%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F_%D0%B6%D0%B8%D0%B7%D0%BD%D1%8C_%D0%93%D0%BB%D0%B0%D0%B2%D0%BD%D1%8B%D0%B5-sample-pdf.acsm?id=NwxaDwAAQBAJ&format=pdf&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api",
},
"webReaderLink": "http://play.google.com/books/reader?id=NwxaDwAAQBAJ&hl=&printsec=frontcover&source=gbs_api",
"accessViewStatus": "SAMPLE",
"quoteSharingAllowed": false,
},
}
You can trust me, all keys are right. And this is my error:
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'imageLinks'
I have done many solution for this error, which I have found. But anything didn't work. Including it:
{% set img = book["volumeInfo"]["imageLinks"] %}
...
<img src={{img["smallThumbnail"]}} class="card-img-top">
a first string worked good, but second was calling error. Please, I need your help
Solution
Privet Vladimir, I saw your comment on my first answer and deleted the first answer. Seems the inner dictionary inside the Jinja object is not being parsed correctly, but I cannot reproduce your bug on my computer. Maybe there are too many levels of nesting. One thing I have had to correct to make it work on my computer are those weird true or false that appear in the response without quotes or capital letters. Maybe this is a side-effect of this problem. Another option I can imagine, is parsing the response from googleapis first in your controller and build a book object with all needed fields at first level and then pass this book object to the jinja template. Hope this helps
Answered By - Mactov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.