Commit 32d56472 authored by Albert Gagalac's avatar Albert Gagalac

Prepared bookshelf/urls.py and views.py for webpage addition + added home page

parent 6db9c8cb
...@@ -35,13 +35,14 @@ ALLOWED_HOSTS = [] ...@@ -35,13 +35,14 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
"bookshelf.apps.BookshelfConfig",
"django.contrib.admin", "django.contrib.admin",
"django.contrib.auth", "django.contrib.auth",
"django.contrib.contenttypes", "django.contrib.contenttypes",
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"bookshelf" #"bookshelf"
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -59,7 +60,7 @@ ROOT_URLCONF = "albertgagalac_reading.urls" ...@@ -59,7 +60,7 @@ ROOT_URLCONF = "albertgagalac_reading.urls"
TEMPLATES = [ TEMPLATES = [
{ {
"BACKEND": "django.template.backends.django.DjangoTemplates", "BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [], "DIRS": [os.path.join(BASE_DIR, 'templates')],
"APP_DIRS": True, "APP_DIRS": True,
"OPTIONS": { "OPTIONS": {
"context_processors": [ "context_processors": [
......
...@@ -17,6 +17,6 @@ from django.contrib import admin ...@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path("bookshelf/", include ('bookshelf.urls', namespace="bookshelf")), path("", include("bookshelf.urls")),
path("admin/", admin.site.urls) path("admin/", admin.site.urls)
] ]
from django.db import models from django.db import models
from django.urls import reverse
from django.core.validators import RegexValidator, MaxValueValidator from django.core.validators import RegexValidator, MaxValueValidator
# Create your models here. # Create your models here.
...@@ -14,7 +15,7 @@ class Author(models.Model): ...@@ -14,7 +15,7 @@ class Author(models.Model):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('author', args=[str(self.name)]) return reverse('author', kwargs={'pk' : self.pk})
class Book(models.Model): class Book(models.Model):
title = models.CharField(default="", max_length=100) title = models.CharField(default="", max_length=100)
...@@ -30,4 +31,4 @@ class Book(models.Model): ...@@ -30,4 +31,4 @@ class Book(models.Model):
return '{}'.format(self.title) return '{}'.format(self.title)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('book', args=[str(self.name)]) return reverse('author', kwargs={'pk' : self.pk})
<p>{{"Widget's Assignments Page"}}<br><br></p>
{% for data in author %}
<p>
first_name: {{data.first_name}}<br>
last_name: {{data.last_name}}<br>
<br>
</p>
{% endfor %}
{% extends 'base.html' %}
{% load static %}
{% block heading %}{% endblock %}
{% block content %}
<h1>Hello World. This is the content</h1>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% comment %} {% block %} {% endblock %} {% endcomment %}
{% block heading %} Welcome to <br>Burt's Database <br>of Favorite Books and Authors {% endblock %}
{% block content %} In the past I used to be an avid reader of <br>
Sci-Fi and Mythology type novels. In more recent times,<br>
I have come to love more manga that deal with <br>
down-to-earth and realistic themes. <br> <br>
tl;dr: I now weeb <br> <br> <br>
Books | Authors
{% endblock %}
{% block list %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import author, BookPageView, home
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', home, name='home'),
path("author/", author, name="author"),
path("books/", BookPageView.as_view(), name="books"),
] ]
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.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Book
# Create your views here. # Create your views here.
def index(request): def home(request):
return HttpResponse('Hello World! This came from the index view') return render(request, 'bookshelf/home.html')
\ No newline at end of file
def author(request):
author = Author.objects.all()
return render(request, 'bookshelf/author.html', {'author' : author})
class BookPageView(View):
def get(self, request):
books = Book.objects.order_by('title')
return render(request, 'bookshelf/books.html', {'books' : books})
<!DOCTYPE html>
<html lang="en">
<head>
<style>
h1 {
text-align: center;
padding-top: 175px;
}
p {
text-align: center;
}
</style>
<link rel="stylesheet" href="style.css">
<title>{% block title %}Burt's Book Bemporium{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<h1>{% block heading %} {% endblock %}</h1>
<div id="content">
<p>{% block content %}{% endblock %}</p>
</div>
{% block list %}{% endblock %}
{% block scripts %}{% endblock %}
</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