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