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

lists/views.py.

def

home_page

(

request

):

if

request

.

method

==

'POST'

:

Item

.

objects

.

create

(

text

=

request

.

POST

[

'item_text'

])

return

redirect

(

'/'

)

items

=

Item

.

objects

.

all

()

return

render

(

request

,

'home.html'

, {

'items'

:

items

})

That does get the unit tests to pass … moment of truth, will the functional test pass?

$

python3 functional_tests.py

[...]

AssertionError: 'To-Do' not found in 'OperationalError at /'

Oops, apparently not. Let’s use another functional test debugging technique, and it’s one

of the most straightforward: manually visiting the site! Open up

http://localhost:

8000

in

your web browser, and you’ll see a Django debug page saying “no such table: lists_item”,

as in

Figure 5-2

.

Figure 5-2. Another helpful debug message

Creating Our Production Database with migrate

Another helpful error message from Django, which is basically complaining that we

haven’t set up the database properly. How come everything worked fine in the unit tests,

Creating Our Production Database with migrate

|

71