Commit 717a9d5f authored by Cheska Hung's avatar Cheska Hung

working urls

parent a37a0dd3
Pipeline #3044 canceled with stages
from django.urls import path
from . import views
from .views import HomeView, BooksListView, BooksDetailView, AuthorListView
from .views import (HomeView, BooksListView, BooksDetailView,
AuthorListView, AuthorDetailView)
urlpatterns = [
path('', views.HomeView, name='home'),
path('home/', views.HomeView, name='home'),
path('books/', BooksListView.as_view(), name='books'),
path('books/<int:pk>/details', BooksDetailView.as_view(),
name='books-detail'),
path('authors/', AuthorListView.as_view(), name='author'),
path('books/<int:pk>/details', BooksDetailView.as_view(),
name='books-detail'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(),
name='author-detail'),
]
......@@ -21,6 +21,12 @@ class BooksDetailView(DetailView):
model = Books
template_name = 'books_details.html'
class AuthorListView(ListView):
model = Author
template_name = 'authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'authors_details.html'
......@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('home/', include('bookshelf.urls', namespace="")),
path('', include('bookshelf.urls', namespace="")),
path('admin/', admin.site.urls),
]
......@@ -7,9 +7,12 @@
{% for Author in object_list %}
<li>
<a href="{{ Author.get_absolute_url }}">
<a href="{% url 'author-detail' Author.pk %}">
{{Author.first_name}} {{Author.last_name}}
</a>
</li>
{% endfor %}
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>{{object.first_name}}{{object.last_name}}</h1>
<h2>{{object.age}}</h2>
<h2>{{object.nationality}}</h2>
<h2>{{object.bio}}</h2>
{% for Books in object_list %}
<li>
<a href="{{ Books.get_absolute_url }}">
{{Books.title}}
</a>
</li>
{% endfor %}
{% endblock content %}
\ No newline at end of file
......@@ -5,8 +5,9 @@
{% block content %}
{% endblock content %}<br>
<a href="books">Books</a>
<a href="authors">authors</a>
<a href="/books">Books</a>
<a href="/authors">authors</a>
<a href="/home">home</a>
</body>
......
......@@ -3,7 +3,7 @@
{% block content %}
{% for Books in object_list %}
<li>
<a href="{{ Books.get_absolute_url }}">
<a href="{% url 'books-detail' Books.pk %}">
{{Books.title}}
</a>
</li>
......
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