Sorry, I mistaked. You can use Detail view. DetailView pass your model data, which named "book"(because model name is Book). Model doesn't list.
2019年11月25日(月) 19:44 Manos Zeakis <[email protected]>: > Hi > > I have declared a model and the simple views I created are working. > > Now I am trying to move to generic views. > > So I added in urls.py > > path('book2/<int:pk>/', views.DetailView.as_view(), name='detail'), > > And in views.py > > class DetailView(generic.DetailView): > model = Book > > And the template is > > {% block content %} > > <h1>book List</h1> > {% if object_list %} > <ul> > {% for book in object_list %} > <li> > {{ book.author }} > </li> > {% endfor %} > </ul> > {% else %} > <p>There are no books in the library.</p> > {% endif %} > > {% endblock %} > > For reference the models.py had been > > class Book(models.Model): > author = models.CharField(max_length=70) > > But the result is "There are no books in the library". So it seems that > the books list is not transferred to the template to be rendered. Could you > help me understand where I have done wrong? > > Thank you > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/0c7de55c-4923-447a-9bf0-0ea962ca3542%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/0c7de55c-4923-447a-9bf0-0ea962ca3542%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADM-sYWb7pijLxKYLH-wsf8i4B9cq0Xkp94cRLkNM_TrC6dVYQ%40mail.gmail.com.

