diff --git a/textbook/chap5.md b/textbook/chap5.md index d2e5913..6e6760d 100644 --- a/textbook/chap5.md +++ b/textbook/chap5.md @@ -389,4 +389,37 @@ def home_page(request): return render(request=request, template_name='home.html', context={'items': items}) # pass items into template using render +``` + +## 5.9 Creating Our Production Database with migrate + +If use FT `functional_tests.py` to verify, will return an error `no such table: lists_item` + +Why? Because Django creates test database for unit tests, this database cannot be used by FT. + +Migrate the database using `python manage.py migrate` + +`functional_tests.py` Test Result: + +``` +AssertionError: '2: Use peacock feathers to make a fly' not found in ['1: Buy peacock feathers', '1: Use peacock feathers to make a fly'] +``` + +* Problem: need to get list numbering right. +* Solution: using Django template tag, `forloop.counter` in template `home.html` + +```html +
{{ forloop.counter }}: {{ item.text }} |