0

The books are being displayed but when i click on the link it does not lead to the google books.co.in webpage where the book is stored, it displays that the page is not found.

my views.py

def books(request):
    if request.method == "POST":
        form=DashboardForm(request.POST)
        text=request.POST['text']
        url="https://www.googleapis.com/books/v1/volumes?q="+text
        r = requests.get(url)
        answer = r.json()
        result_list = []
        for i in range(10):
            result_dict = {
                'title':answer['items'][i]['volumeInfo']['title'],
                'subtitle':answer['items'][i]['volumeInfo'].get('subtitle'),
                'description':answer['items'][i]['volumeInfo'].get('description'),
                'count':answer['items'][i]['volumeInfo'].get('pageCount'),
                'categories':answer['items'][i]['volumeInfo'].get('categories'),
                'rating':answer['items'][i]['volumeInfo'].get('pageRating'),
                'thumbnail':answer['items'][i]['volumeInfo'].get('imageLinks').get('thumbnail'),
                'preview':answer['items'][i]['volumeInfo'].get('previewLinks')
                
            }
            result_list.append(result_dict)
            context={
                'form' : form,
                'results' :result_list
            }
        return render(request,'dashboard/books.html',context)
    else:
        form=DashboardForm() 
    context={'form' : form}
    return render(request,'dashboard/books.html',context)

my books.html template

{% extends 'dashboard/base.html' %} 
{% load static %} 
{% block content %}

<section class='text-center container'>
    <h2><b>SEARCH FOR BOOKS </b></h2>
    <p>Enter the search query to obtain your desired book</p><b></b>
    <form action="" method="post">
        {% csrf_token %}
        {{form}}
        <input class="btn btn-danger" type="submit" value="Submit">
    </form><br>

    {% for result in results %}
    <a href="{{result.preview}}" target="_blank">
        <div class="card">
            <div class="card-header">   
                <div class="row">
                    <div class="col-md-3">
                        <img class="img-fluid" src="{{result.thumbnail}}" alt="">

                    </div>
                    <div class="col-md-9">
                        <h3 class="p-0 m-0">{{result.title}}</h3>
                        <b>
                            <u>
                                <h5 class="p-0 m-0">{{result.subtitle}}</h5>
                            </u>
                        </b>
                        {% if result.description %}
                            <h6 class="p-0 m-1">{{result.description}}</h6>
                        {% endif %}

                        <b> 

                        {% if result.categories %}    
                            <h6 class="ml-0 mt-3">Category: 
                                {% for category in result.categories %}
                                    {{category}}
                                {% endfor %}
                            </h6>
                        {% endif %}

                        {% if result.count %}    
                            <h6 class="ml-0 mt-1">Pages: {{result.count}}</h6>
                        {% endif %}

                        {% if result.rating %}
                            <h6 class="ml-0 mt-1">Rating:{{result.rating}}</h6>
                        {% endif %}
                        </b>
                    </div>
                </div>
            </div>
        </div>
    </a>
    {% endfor %}
    <br>
</section>

{% endblock content %}

I have installed and imported requests and want to redirect to google books page when i click on the book. enter image description here

0 Answers0