Commit f6d37cfc authored by KaoruSawade's avatar KaoruSawade

Updated views.py and urls.py to implement home page via FBV, & authors page...

Updated views.py and urls.py to implement home page via FBV, & authors page and per authors page in CBV
parent b1a9d5ce
from django.urls import path from django.urls import path
from .views import home, books, authors from .views import home, AuthorListView, AuthorDetailView
urlpatterns = [ urlpatterns = [
path('home/', home, name='home'), path('home/', home, name='home'),
path('books/', books, name='books'), path('authors/', AuthorListView.as_view(), name='author-list'),
path('authors/', authors, name='authors'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Author, Books
def home(request): def home(request):
return render(request, 'bookshelf/home.html') return render(request, 'bookshelf/home.html', {'name': 'Carlos'})
def books(request): class AuthorListView(ListView):
return render(request, 'bookshelf/books.html') def get(self, request):
author_list = Author.objects.all()
return render(request, 'bookshelf/author_list.html', {'name': 'Carlos', 'author_list': author_list})
def authors(request): class AuthorDetailView(DetailView):
return render(request, 'bookshelf/authors.html') def get(self, request, pk):
\ No newline at end of file author = Author.objects.get(pk=pk)
book_list = Books.objects.filter(author__first_name__exact=author.first_name)
return render(request, 'bookshelf/author_detail.html', {'author': author, 'book_list': book_list})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment