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 .views import home, books, authors
from .views import home, AuthorListView, AuthorDetailView
urlpatterns = [
path('home/', home, name='home'),
path('books/', books, name='books'),
path('authors/', authors, name='authors'),
path('authors/', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
]
app_name = "bookshelf"
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):
return render(request, 'bookshelf/home.html')
return render(request, 'bookshelf/home.html', {'name': 'Carlos'})
def books(request):
return render(request, 'bookshelf/books.html')
class AuthorListView(ListView):
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):
return render(request, 'bookshelf/authors.html')
\ No newline at end of file
class AuthorDetailView(DetailView):
def get(self, request, pk):
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