jacklondon
jacklondon

Reputation: 155

Django - The page don't load after click

i'm new in Django developing. I'm following the tutorial about Library on MDN (https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django) Until i follow the code all work but i'm trying implement author page by myself. Probably is very stupid issue but is one day that i'm turning around like a dog with its tail. There is 2 page: author_list and author detail. I set urls.py (in my project) i set view.py and crate my template. I follow the same step of tutorial for realize book_list and book_detail but when i click on my author the page don't go to the detail of that author and stay in author_list.html.

Here the code urls.py :

path('authors/', views.AuthorListView.as_view(), name='authors'),
path('author/<int:pk>', views.AuthorDetailView.as_view(), name='author-detail'),

Here views.py:

class AuthorListView(generic.ListView):
    model = Author

class AuthorDetailView(generic.ListView):
    model = Author

Here author_list.html with link get_absolute_url:

{% extends "base_generic.html"%}

{% block content %}

 <h1>Author list</h1>
{% if author_list %}
<ul>
    {% for aut in author_list %}
    <li><a href="{{ aut.get_absolute_url }}">{{ aut.first_name }} - {{ aut.last_name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>There are no author.</p>
{% endif %}
{% endblock %}

Here author_detail.html:

{% extends "base_generic.html" %}
{% block content %}
  <h1>Author</h1>
{% if author %}
<p><strong>Nome: </strong> {{ author }}</p>
<p><strong>Nato il : </strong> {{ author.date_of_birth }}</p>
<p><strong>Morto il : </strong> {{ author.date_of_death }}</p>
{% endif %}
{% endblock %}

Here the screenshot

Author_list.html before click url=catalog/authors/

After click url change but page not

Thank to all for help

Upvotes: 0

Views: 150

Answers (2)

Myroslav Hryshyn
Myroslav Hryshyn

Reputation: 726

I believe you need DetailView instead of ListView for AuthorDetailView.

Upvotes: 1

Robin Zigmond
Robin Zigmond

Reputation: 18249

Looks like a typo to me, you want generic.DetailView (instead of ListView) for the author/<int:pk> path.

I also don't think it's right to extend base_generic for the template for the detail view. But that depends exactly what is in this base template.

Upvotes: 0

Related Questions