7.5.2 A New View Function

chap7-new
Jason Zhu 2020-11-11 13:33:55 +11:00
parent 4d0f9a6976
commit d2d72da60d
2 changed files with 8 additions and 6 deletions

View File

@ -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):

View File

@ -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
context={'items': items}) # pass items into template using render
def view_list(request):
items = Item.objects.all()
return render(request, 'home.html', {'items': items})