Commit 1b9b05cd authored by Jan Ericsson Ong Ang's avatar Jan Ericsson Ong Ang

edited urls.py and views.py

parent b6d8c359
{% extends 'base.html' %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ author.first_name }} {{ author.last_name }}{% endblock %}
{% block header %}{{ author.first_name }} {{ author.last_name }}{% endblock %}
{% block content %}
{% block header %}<h1>{{ author.first_name }} {{ author.last_name }}</h1>{% endblock %}
<p>{{ author.age }}</p>
<p>{{ author.nationality }}</p>
<p>{{ author.bio }}</p>
<p>Books by {{ author.first_name }} {{ author.last_name }} I love</p>
<a href="/books/1/details">Home</a><br>
<a href="/bookshelf/books/1/details/">Home</a><br>
<a href="/homepage/">Home</a>&nbsp;&nbsp;
<a href="/books/">Books</a>&nbsp;&nbsp;
<a href="/authors/">Authors</a>
<a href="/bookshelf/">Home</a>&nbsp;&nbsp;
<a href="/bookshelf/books/">Books</a>&nbsp;&nbsp;
<a href="/bookshelf/author/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block header %},{% nickname %}'s Favorite Authors:{% endblock %}
{% block content %}
{% block header %}<h1>{{ nickname }}'s Favorite Authors:</h1>{% endblock %}
<br>
{% for author in authors %}
<a href="/author/{{ author.pk }}/details/">{{ author.first_name }} {{ author.last_name }}</a>
<a href="/bookshelf/author/{{ author.pk }}/details/">{{ author.first_name }} {{ author.last_name }}</a>
{% endfor %}
<br>
<a href="/homepage/">Home</a>&nbsp;&nbsp;
<a href="/books/">Books</a>
<a href="/bookshelf/">Home</a>&nbsp;&nbsp;
<a href="/bookshelf/books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block header %}{% nickname %}'s Favorite Books:{% endblock %}
{% block content %}
{% block header %}<h1>{{ nickname }}'s Favorite Books:</h1>{% endblock %}
<br>
{% for book in books %}
<a href="/books/{{ book.pk }}/details/">{{ book.title }}</a>
<a href="/bookshelf/books/{{ book.pk }}/details/"><p>{{ book.title }}</p></a>
{% endfor %}
<br>
<a href="/homepage/">Home</a>&nbsp;&nbsp;
<a href="/authors/">Authors</a>
<a href="/bookshelf/">Home</a>&nbsp;&nbsp;
<a href="/bookshelf/author/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books & Authors!{% endblock %}
{% block header %}Welcome to {% nickname %}'s Database of Favorite Books and Author's! {% endblock %}
{% block title %}My Favorite Books & Authors!{% endblock %}
{% block content %}
{% block header %}<h1>Welcome to {{ nickname }}'s Database of Favorite Books and Author's!</h1>{% endblock %}
<p>
I love fiction novels that are able to tell a story really well. A book that is able to keep me interested throughout every page is what I love!
</p>
<a href="/books/">Books</a>
<a href="/bookshelf/books/">Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/authors/">Authors</a>
<a href="/bookshelf/author/">Authors</a>
{% endblock %}
\ No newline at end of file
......@@ -6,7 +6,9 @@ from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetail
urlpatterns = [
path('', HomeView.as_view(), name='home'),
path('author/', AuthorView.as_view(), name='author'),
path('author/<int:pk>/', AuthorDetailView.as_view(), name='author-detail'),
path('author/<int:pk>/details/', AuthorDetailView.as_view(), name='author-detail'),
path('books/', BooksView.as_view(), name='books'),
path('books/<int:pk>/', BookDetailView.as_view(), name='books-detail'),
]
\ No newline at end of file
path('books/<int:pk>/details/', BookDetailView.as_view(), name='books-detail'),
]
app_name = 'bookshelf'
\ No newline at end of file
......@@ -8,11 +8,12 @@ from .models import Author, Books
class HomeView(View):
def get(self, request):
return render(request, 'bookshelf/templates/bookshelf/home.html', {'nickname': 'Jan'})
return render(request, 'bookshelf/home.html', {'nickname': 'Jan'})
class AuthorView(ListView):
model = Author
template_name = 'bookshelf/templates/bookshelf/author.html'
def get(self, request):
return render(request, 'bookshelf/author.html', {'nickname': 'Jan'})
class AuthorDetailView(DetailView):
model = Author
......@@ -20,7 +21,8 @@ class AuthorDetailView(DetailView):
class BooksView(ListView):
model = Books
template_name = 'bookshelf/books.html'
def get(self, request):
return render(request, 'bookshelf/books.html', {'nickname': 'Jan'})
class BookDetailView(DetailView):
model = Books
......
......@@ -56,7 +56,7 @@ ROOT_URLCONF = 'janang_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -117,8 +117,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = '/templates/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'templates')]
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
......
......@@ -18,5 +18,5 @@ from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path("bookshelf/", include("bookshelf.urls")),
path("bookshelf/", include("bookshelf.urls", namespace = 'bookshelf')),
]
......@@ -9,6 +9,6 @@
<div id="contetnt">
{% block content %}{% endblock %}
</div>
{block scripts %}{% 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