Comments on tutorial: 03-views-and-templates.rst
We don't have a home page (/) but... we have an admin page (/admin/) !
In the Home page test paragraph, after this sentence:
If we run our tests now this test should fail because we haven't created a homepage yet.
Since we saw we already have a page up aand running, the admin, show how a similar test succeeds for an existing page, by adding this test:
def test_adminpage(self):
response = self.client.get('/admin/')
self.assertEqual(response.status_code, 200)
Distinction between myblog and blog:
In the following paragraph we explain (do we really explain?) that we are creating a view in the myblog project directory as opposed to the blog app dirctory:
Important
We are making this views file in the myblog project directory (next to the myblog/urls.py file we are about to change). We are not changing the blog/views.py file yet. We will use that file later.
But when time comes for testing, we run a test that was previously setup in the blog app directory:
Great! Now let's make sure our new test passes:
$ python manage.py test blog
Should we be consistent and have a testfile at the myblog project level ?
Would the following command then work ?
$ python manage.py test myblog
Well I guess not!:
ImproperlyConfigured: App with label myblog could not be found
Just to create a very simple home page we need all of the following:
- Foundation
- Static directory
- static/css/foundation.css file .............................. from Foundation
- Templates directory
- templates/index.html ........................................ using {% load %} and {% static %} tags
- myblog/views.py with a class-based view defined at the project level
- a new pattern in /myblog/urls.py ........................ url( r'^$', views.home), )
That's a lot of copy-pasting before seeing anything new!
Could we break this down into incremental steps ?
The home page does not need to be called index.html. Right?
Name it home1.html and change:
template_name = 'index.html' to template_name = 'home1.html'
This might help show there is no webserver convention here to look for and serve a specific file in the / directory. But the combination of url pattern and the view settings end up picking the right file.
Also: change the settings for template_name successively to:
home1.html, base.html and index.html to see how things build up