/Users/nnn/django_exercises/mysite/templates/polls/index.html is the wrong location, it should be $$/django_polls/polls/templates/polls/index.html.
2. What is polls/poll_list.html? Nowhere in the tutorial ever created this file, no?polls/index.html, polls/poll_list.html
| Request Method: | GET |
|---|---|
| Request URL: | http://127.0.0.1:8000/polls/ |
| Django Version: | 1.5.1 |
| Exception Type: | TemplateDoesNotExist |
| Exception Value: | polls/index.html, polls/poll_list.html |
| Exception Location: | /Library/Python/2.7/site-packages/django/template/loader.py in select_template, line 194 |
| Python Executable: | /usr/bin/python |
| Python Version: | 2.7.2 |
| Python Path: | ['/Users/nnn/django_exercises/mysite', '/Users/nnn/py_pkg/lib/python/django_polls-0.1-py2.7.egg', '/Users/nnn/py_pkg/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] |
| Server time: | Fri, 26 Jul 2013 16:59:14 -0700 |
Django tried loading these templates, in this order:
django.template.loaders.filesystem.Loader:
/Users/nnn/django_exercises/mysite/templates/polls/index.html, polls/poll_list.html (File does not exist)django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/auth/templates/polls/index.html, polls/poll_list.html (File does not exist)/Library/Python/2.7/site-packages/django/contrib/admin/templates/polls/index.html, polls/poll_list.html (File does not exist)We’re using two generic views here: object_list() and object_detail(). Respectively, those two views abstract the concepts of “display a list of objects” and “display a detail page for a particular type of object.”
- Each generic view needs to know what data it will be acting upon. This data is provided in a dictionary. The queryset key in this dictionary points to the list of objects to be manipulated by the generic view.
- The object_detail() generic view expects the ID value captured from the URL to be called "object_id", so we’ve changed poll_id to object_id for the generic views.
- We’ve added a name, poll_results, to the results view so that we have a way to refer to its URL later on (see the documentation about naming URL patterns for information). We’re also using the url() function fromdjango.conf.urls.defaults here. It’s a good habit to use url() when you are providing a pattern name like this.
By default, the object_detail() generic view uses a template called <app name>/<model name>_detail.html. In our case, it’ll use the template "polls/poll_detail.html". Thus, rename your polls/detail.html template to polls/poll_detail.html, and change the render_to_response() line in vote().
Similarly, the object_list() generic view uses a template called <app name>/<model name>_list.html. Thus, renamepolls/index.html to polls/poll_list.html.
Because we have more than one entry in the URLconf that uses object_detail() for the polls app, we manually specify a template name for the results view: template_name='polls/results.html'. Otherwise, both views would use the same template. Note that we use dict() to return an altered dictionary in place.
On Saturday, July 27, 2013 8:20:26 AM UTC+8, Cate Liu wrote:We’re using two generic views here: object_list() and object_detail(). Respectively, those two views abstract the concepts of “display a list of objects” and “display a detail page for a particular type of object.”
- Each generic view needs to know what data it will be acting upon. This data is provided in a dictionary. The queryset key in this dictionary points to the list of objects to be manipulated by the generic view.
- The object_detail() generic view expects the ID value captured from the URL to be called "object_id", so we’ve changed poll_id to object_id for the generic views.
- We’ve added a name, poll_results, to the results view so that we have a way to refer to its URL later on (see the documentation about naming URL patterns for information). We’re also using the url() function fromdjango.conf.urls.defaults here. It’s a good habit to use url() when you are providing a pattern name like this.
By default, the object_detail() generic view uses a template called <app name>/<model name>_detail.html. In our case, it’ll use the template "polls/poll_detail.html". Thus, rename your polls/detail.html template to polls/poll_detail.html, and change the render_to_response() line in vote().
Similarly, the object_list() generic view uses a template called <app name>/<model name>_list.html. Thus, renamepolls/index.html to polls/poll_list.html.
Because we have more than one entry in the URLconf that uses object_detail() for the polls app, we manually specify a template name for the results view: template_name='polls/results.html'. Otherwise, both views would use the same template. Note that we use dict() to return an altered dictionary in place.
/home/user/website/myweb/polls/templates/polls/index.html, polls/poll_list.html (File does not exist)Django tried loading these templates, in this order:
django.template.loaders.filesystem.Loader:/home/user/website/myweb/templates/polls/index.html, polls/poll_list.html (File does not exist)django.template.loaders.app_directories.Loader:/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/polls/index.html, polls/poll_list.html (File does not exist)/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/polls/index.html, polls/poll_list.html (File does not exist)/home/user/website/myweb/polls/templates/polls/index.html, polls/poll_list.html (File does not exist)/home/user/website/myweb/polls/templates/polls/index.html, polls/poll_list.html (File exists)'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader'
'django.template.loaders.eggs.Loader',
TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', 'django.template.loaders.eggs.Loader')