Answer the question
In order to leave comments, you need to log in
How to pass Url template to DetailView?
Hello. I just started learning Django and I have a question.
Here is urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^books/$', views.BookListView.as_view(), name='books'),
url(r'^book/(?P<pk>\d+)$', views.BookDetailView.as_view(), ),
url(r'^authors/$', views.AuthorListView.as_view(), name='authors'),
url(r'^author/(?P<pk>\d+)$', views.AuthorDetailView.as_view(), name='author-detail')
]
class BookListView(generic.ListView):
model = Book
paginate_by = 10
class BookDetailView(generic.DetailView):
model = Book
class AuthorListView(generic.ListView):
model = Author
class AuthorDetailView(generic.DetailView):
model = Author
Answer the question
In order to leave comments, you need to log in
how do i pass pk to views.py using DetailView&
urlpatterns = [
path('', views.index, name='index'),
path('books/', views.BookListView.as_view(), name='books'),
path('book/<int:pk>/', views.BookDetailView.as_view(), ),
path('authors/', views.AuthorListView.as_view(), name='authors'),
path('author/<int:pk>/', views.AuthorDetailView.as_view(), name='author-detail')
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question