每当我尝试在 urls.py 中添加 <int:pk> 时,在 Django 中找不到页面 (404)

Page not found (404) in Django, whenever I tried adding <int:pk> in urls.py

我想要实现的是在用户单击产品时在 url 中显示产品 ID。所以我尝试将 <int:pk> 放在 url 中,但它说,

Page Not Found (404)
    Request Method: GET
    Request URL: http://127.0.0.1:8000/book-details/

homepage.html

{% for book in random %}
     <a type="submit" href="{{% url 'book-details' %}}">
         <img src="{{book.cover.url}}" height="300px" width="200px">
     </a>
{% endfor %}

views.py

def book_details(request,pk):
    return render(request, 'book-details.html')

urls.py

urlpatterns = [
path('admin/', admin.site.urls),
path('', homepage, name='home'),
path('fiction', fiction, name='fiction'),
path('nonfiction', nonfiction, name='nonfiction'),
path('book-details/<int:pk>/', book_details, name='book-details'),
path('search-result', search_result, name='search-result')

您在调用视图时未传递 <int:pk>,请在 homepage.html 中进行以下更改:添加此代码

<a href="{% url 'book-details' book.pk %}"