'Book' object is not iterable

This line tries to iterate over a variable called book_list.

However BookDetailView puts a single book into the context, in the variable name you give it:

I would suggest using context_object_name = 'book', then in your template don’t use a for loop, but refer to the single book in the variable book only. e.g.

{% extends 'base.html' %} {% block content %}

<div class="container">
  <div class="row">
    <div class="col">
      <h1>{{ book.title }}</h1>
    </div>
  </div>
</div>

{% endblock content %}
1 Like