Initialized views and urls for the .html files

parent 747fb85a
from django.urls import path from django.urls import path
from .views import index from .views import home_view, BooksView, BooksDetailView, AuthorView, AuthorDetailView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', home_view, name='home'),
path('books', BooksView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book-details'),
path('author', AuthorView.as_view(), name='author'),
path('author/<int:pk>/details/', AuthorDetailView.as_view(), name='author-details'),
] ]
# This might be needed depending on your Django version # This might be needed depending on your Django version
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views import View
from django.http import HttpResponse def home_view(request):
def index(request): return render(request, 'bookshelf/home.html', {})
return HttpResponse('Hello World! This came from the index view')
class HomeView(View):
def get(self,request):
return render(request, 'bookshelf/home.html', {})
class BooksView(View):
def get(self,request):
return render(request, 'bookshelf/books.html', {})
class BooksDetailView(View):
def get(self,request):
return render(request, 'bookshelf/books_detail.html', {})
class AuthorView(View):
def get(self,request):
return render(request, 'bookshelf/author.html', {})
class AuthorDetailView(View):
def get(self,request):
return render(request, 'bookshelf/author_details.html', {})
\ 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