django.urls.exceptions.NoReverseMatch: Reverse for 'book_index' with arguments '('b1',)' not found. 1 pattern(s) tried: ['book/(?P<pk>[0-9]+)/index\\Z']
ページのイメージとしてはbook_title.htmlで本のタイトル一覧が出てきて、クリックすると、その本の目次のページ(book_index.html)が出てくるといった感じです。
このようなエラーが出たので、urls.pyのBookIndexViewのpathと、views.pyのBookIndexViewクラスをコメントアウトしました。しかし、それでも同じエラーが出ています。
python
1#urls.py 2コード 3from django.urls import path 4from app import views 5 6urlpatterns = [ 7 path('',views.BookTitleView.as_view(), name = 'book_title'), 8 path('book/<int:pk>/index',views.BookIndexView.as_view(), name = 'book_index'), 9]
python
1#views.py 2コード 3from django import views 4from django.views.generic import View 5from django.shortcuts import render 6from .models import BookData, Miosie 7 8# Create your views here. 9class BookTitleView(View): 10 def get(self, request, *args, **kwargs): 11 book_data = BookData.objects.order_by('id') 12 return render(request, 'app/book_title.html',{ 13 'book_data': book_data 14 }) 15 16class BookIndexView(View): 17 def get(self, request, *args, **kwargs): 18 index_data = Ronbun.objects.order_by('id').filter(book_id = self.kwargs['book_id']) 19 return render(request, 'app/book_index.html',{ 20 'index_data': index_data 21 }) 22
html
1<!--book_title.html--> 2コード 3{% extends "app/base.html" %} 4{% block content %} 5 6{% for bookD in book_data %} 7<div class="book_title"> 8 <a href="{% url 'book_index' bookD.book_id%}">{{bookD.book_id}}</a> 9</div> 10{% endfor %} 11 12{% endblock %}
html
1<!--book_index.html--> 2コード 3{% extends "app/base.html" %} 4{% block content %} 5 6{% for indexD in index_data %} 7<div class="book_title"> 8 {{indexD.title}} 9</div> 10{% endfor %} 11 12{% endblock %} 13

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。