Hi there,

I was trying today just for myself learning to get data from google books 
api https://www.googleapis.com/books/v1/volumes/ without needed auth key 
but the point is that I'm getting no results. I've tried with single book 
(like below), tried to get books that title contains "something" but django 
is giving me key errors when I'm trying to display it on view. Could you 
please tell me how to make this work with Django? I know it should be 
simple but still gettings those errors

Exception Type: KeyError
Exception Value: 

'title'


import requests

def api(request):
    response = 
requests.get('https://www.googleapis.com/books/v1/volumes/YyXoAAAACAAJ')
    book = response.json()
    return render(request, 'books/api.html', {
        'title': book['title'],
        'authors': book['authors']
    })

and here is html

{% block content %}
  <h2>Google books API</h2>
  <form method="get">
    <input type="text" name="book">
    <button type="submit">search on google books api</button>
  </form>
  {% if book %}
      <p>
        <strong>{{ book.title }} {{ book.authors }}
      </p>
  {% endif %}
{% endblock %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/33d9a047-ffa5-45fe-a320-cfe8f7124cba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to