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