Commit 162c3d21 authored by Almira Redoble's avatar Almira Redoble

Created working views and templates for home, author-list, and book-list.

parent 1109196e
......@@ -58,7 +58,7 @@ ROOT_URLCONF = 'almiraredoble_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -122,6 +122,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
......@@ -18,5 +18,5 @@ from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('', include('bookshelf.urls', namespace="bookshelf")),
]
{% extends 'base.html' %}
{% load static %}
{% block header %}
<title>My Favorite Authors</title>
{% endblock %}
{% block heading %}
Almira's Favorite Authors:
{% endblock %}
{% block content %}
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block header %}
<title>My Favorite Books</title>
{% endblock %}
{% block heading %}
Almira's Favorite Books:
{% endblock %}
{% block content %}
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.title }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block header %}
<title>{{ header }}</title>
{% endblock %}
{% block heading %}
{{ heading }}
{% endblock %}
{% block content %}
{{ content }}
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import (
HomePageView, BookListView, BookDetailView,
AuthorListView, AuthorDetailView
)
urlpatterns = [
path('', index, name='index'),
path('home/', HomePageView, name='home'),
path('books/', BookListView.as_view(), name='books'),
path('authors/', AuthorListView.as_view(), name='authors'),
]
app_name = "bookshelf"
\ No newline at end of file
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
def index(request):
return HttpResponse('test')
# Create your views here.
from .models import Books, Author
def HomePageView(request):
title = "My Favorite Books & Authors"
heading = "Welcome to Almira's Database of Favorite Books and Authors!"
content = "I judge books by their covers, so anything that gives my "\
"eyes a spark of joy is something I would read. The most recent " \
"books I've read are classics, born out of a need to know what most " \
"people already know. "
return render(request, 'bookshelf/home.html', {
'header': title,
'heading': heading,
'content': content,
})
class BookListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BookDetailView(DetailView):
model = Books
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<div id="header">
{% block header %}{% endblock %}
</div>
</head>
<body>
<div id="heading">
{% block heading %}{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
<div id="footer">
{% block footer %}{% endblock %}
</div>
</body>
</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