@@ -488,8 +488,11 @@ NOTE: If you've never come across regular expressions, you can get away with
488
488
just taking my word for it, for now-- but you should make a mental note to
489
489
go learn about them.
490
490
491
- We'll also get rid of the admin URL, because we won't be using the Django
492
- admin site for now:
491
+ We'll make a couple of changes to what we import and to what we test. First,
492
+ we don't need to import the `admin` module from `django.contrib` , but we do
493
+ need to import the `views` module from `lists` . Second, we'll rewrite the
494
+ URL pattern to use the empty-string expression instead of the `admin` URL,
495
+ since we won't be using the Django admin site for now:
493
496
494
497
495
498
[role="sourcecode dofirst-ch03l003"]
@@ -597,7 +600,7 @@ with HTML to the browser. Open up 'lists/tests.py', and add a new
597
600
----
598
601
from django.urls import resolve
599
602
from django.test import TestCase
600
- from django.http import HttpRequest
603
+ from django.http import HttpRequest #<1>
601
604
602
605
from lists.views import home_page
603
606
@@ -621,12 +624,13 @@ class HomePageTest(TestCase):
621
624
622
625
What's going on in this new test?
623
626
624
- <1> We create an `HttpRequest` object, which is what Django will see when
625
- a user's browser asks for a page.
627
+ <1> We import the `HttpRequest` class so that we can then create an
628
+ `HttpRequest` object within our test. When a user's browser asks for a
629
+ page, Django will see that object.
626
630
627
- <2> We pass it to our `home_page` view, which gives us a response. You won't be
628
- surprised to hear that this object is an instance of a class called
629
- `HttpResponse` .
631
+ <2> We pass the `HttpRequest` object to our `home_page` view, which gives us a
632
+ response. You won't be surprised to hear that the response is an instance
633
+ of a class called `HttpResponse` .
630
634
631
635
<3> Then, we extract the `.content` of the response. These are the raw bytes,
632
636
the ones and zeros that would be sent down the wire to the user's browser.
0 commit comments