From d2d72da60de5cb379b3a91257294af7f92715fa2 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Wed, 11 Nov 2020 13:33:55 +1100 Subject: [PATCH] 7.5.2 A New View Function --- src/lists/tests.py | 6 +++--- src/lists/views.py | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lists/tests.py b/src/lists/tests.py index 83eda0f..094e1dc 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -49,10 +49,10 @@ class ListViewTest(TestCase): Item.objects.create(text="itemey 1") Item.objects.create(text="itemey 2") - response = self.client.get('/lists/the-only-list-in-the-world') + response = self.client.get('/lists/the-only-list-in-the-world/') - self.assertIn('itemey 1', response.content.decode()) - self.assertIn('itemey 2', response.content.decode()) + self.assertContains(response, 'itemey 1') + self.assertContains(response, 'itemey 2') class ItemModelTest(TestCase): diff --git a/src/lists/views.py b/src/lists/views.py index b5318bb..ae78ba5 100644 --- a/src/lists/views.py +++ b/src/lists/views.py @@ -1,5 +1,3 @@ -from django.http.request import HttpRequest -from django.http.response import HttpResponse from django.shortcuts import redirect, render from lists.models import Item @@ -13,4 +11,8 @@ def home_page(request): items = Item.objects.all() # get objects from database (model) return render(request=request, template_name='home.html', - context={'items': items}) # pass items into template using render \ No newline at end of file + context={'items': items}) # pass items into template using render + +def view_list(request): + items = Item.objects.all() + return render(request, 'home.html', {'items': items}) \ No newline at end of file