Commit 9fbb8919 authored by Angelo Alvarez's avatar Angelo Alvarez

Created ListView for Model Books

parent b4f04fc0
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Alva's Favorite Books</h1>
<ul>
{% for book in books %}
<li><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></li>
{% endfor %}
</ul>
<hr>
<div id="links" style="margin: auto; text-align: center; width: 100%">
<a href="../home/">Home</a>
&nbsp; &nbsp;
<a href="../authors/">Authors</a>
</div>
{% endblock %}
from django.urls import path from django.urls import path
from .views import home from .views import home, BooksListView
urlpatterns = [ urlpatterns = [
path('home/', home, name='home'), path('home/', home, name='home'),
path('books/', BooksListView.as_view(), name='books')
] ]
# This might be needed, depending on your Django version # This might be needed, depending on your Django version
......
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 Books
# Create your views here. # Create your views here.
def home(request): def home(request):
return render(request, 'events/home.html') return render(request, 'events/home.html')
\ No newline at end of file
class BooksListView(View):
model = Books
def get(self, request):
booklist = Books.objects.all()
return render(request, 'events/books.html', {'books' : booklist})
\ 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