4.3.1 Refactoring to Use a Template

chap4
Jason Zhu 2020-11-07 20:48:41 +11:00
parent 4f7cb1bb5a
commit 89224c9928
4 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1,3 @@
<html>
<title>To-Do lists</title>
</html>

View File

@ -23,5 +23,5 @@ class HomePageTest(TestCase):
response = home_page(request) #2
html = response.content.decode('utf8') #3
self.assertTrue(html.startswith('<html>')) #4
self.assertIn('<title>To-Do list</title>', html) #5
self.assertTrue(html.endswith('</html>')) #4
self.assertIn('<title>To-Do lists</title>', html.strip()) #5
self.assertTrue(html.strip().endswith('</html>')) #4

View File

@ -4,5 +4,8 @@ from django.shortcuts import render
# Create your views here
def home_page(request):
# return HttpResponse('<html><title>To-Do lists</title></html>')
return HttpResponse('<html><title>To-Do list</title></html>')
"""
Using render function to take a request and name of the template to render
"""
return render(request, 'home.html')

View File

@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lists'
]
MIDDLEWARE = [