Background Image
Table of Contents Table of Contents
Previous Page  57 / 478 Next Page
Information
Show Menu
Previous Page 57 / 478 Next Page
Page Background

superlists/urls.py.

urlpatterns

=

patterns

(

''

,

# Examples:

url

(

r'^$'

,

'superlists.views.home'

,

name

=

'home'

),

# url(r'^blog/', include('blog.urls')),

# url(r'^admin/', include(admin.site.urls)),

)

Run the unit tests again, with

python3 manage.py test

:

ImportError: No module named 'superlists.views'

[...]

django.core.exceptions.ViewDoesNotExist: Could not import

superlists.views.home. Parent module superlists.views does not exist.

That’s progress! We’re no longer getting a 404; instead Django is complaining that the

dot-notation

superlists.views.home

doesn’t point to a real view. Let’s fix that, by

pointing it towards our placeholder

home_page

object, which is inside

lists

, not

superlists

:

superlists/urls.py.

urlpatterns

=

patterns

(

''

,

# Examples:

url

(

r'^$'

,

'lists.views.home_page'

,

name

=

'home'

),

And run the tests again:

django.core.exceptions.ViewDoesNotExist: Could not import

lists.views.home_page. View is not callable.

The unit tests have made the link between the URL

/

and the

home_page = None

in

lists/

views.py

, and are now complaining that

home_page

isn’t a callable; ie, it’s not a function.

Nowwe’ve got a justification for changing it frombeing

None

to being an actual function.

Every single code change is driven by the tests. Back in

lists/views.py

:

lists/views.py.

from

django.shortcuts

import

render

# Create your views here.

def

home_page

():

pass

And now?

$

python3 manage.py test

Creating test database for alias 'default'...

.

---------------------------------------------------------------------

Ran 1 test in 0.003s

OK

Destroying test database for alias 'default'...

Hooray! Our first ever unit test pass! That’s so momentous that I think it’s worthy of a

commit:

urls.py

|

29