VelogaWhite commited on
Commit
01418ad
·
1 Parent(s): 58b6f20

Refactor homepage view to use a template

Browse files
lists/templates/home.html ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ <html>
2
+ <title>To-Do lists</title>
3
+ </html>
lists/tests.py CHANGED
@@ -1,11 +1,11 @@
1
  from django.test import TestCase
2
- from django.http import HttpRequest
3
- from lists.views import home_page
4
 
5
 
6
  class HomePageTest(TestCase):
7
- def test_home_page_returns_correct_html(self):
8
  response = self.client.get("/")
9
- self.assertContains(response, "<title>To-Do lists</title>")
10
- self.assertContains(response, "<html>")
11
- self.assertContains(response, "</html>")
 
 
 
1
  from django.test import TestCase
 
 
2
 
3
 
4
  class HomePageTest(TestCase):
5
+ def test_uses_home_template(self):
6
  response = self.client.get("/")
7
+ self.assertTemplateUsed(response, "home.html")
8
+
9
+ def test_renders_homepage_content(self):
10
+ response = self.client.get("/")
11
+ self.assertContains(response, "To-Do")
lists/views.py CHANGED
@@ -1,4 +1,5 @@
1
- from django.http import HttpResponse
 
2
 
3
  def home_page(request):
4
- return HttpResponse("<html><title>To-Do lists</title></html>")
 
1
+ from django.shortcuts import render
2
+
3
 
4
  def home_page(request):
5
+ return render(request, "home.html")
superlists/settings.py CHANGED
@@ -31,12 +31,13 @@ ALLOWED_HOSTS = []
31
  # Application definition
32
 
33
  INSTALLED_APPS = [
34
- 'django.contrib.admin',
35
- 'django.contrib.auth',
36
- 'django.contrib.contenttypes',
37
- 'django.contrib.sessions',
38
- 'django.contrib.messages',
39
- 'django.contrib.staticfiles',
 
40
  ]
41
 
42
  MIDDLEWARE = [
 
31
  # Application definition
32
 
33
  INSTALLED_APPS = [
34
+ "django.contrib.admin",
35
+ "django.contrib.auth",
36
+ "django.contrib.contenttypes",
37
+ "django.contrib.sessions",
38
+ "django.contrib.messages",
39
+ "django.contrib.staticfiles",
40
+ "lists",
41
  ]
42
 
43
  MIDDLEWARE = [