#22912: Possible error in documentation
-------------------------------+--------------------
     Reporter:  cfperea@…      |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Documentation  |    Version:  1.6
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Hi, I've been following the official Django tutorial and came across a
 possible error in the documentation using version 1.6.
 In the section titled ''The Django test client''
 ([https://docs.djangoproject.com/en/1.6/intro/tutorial05/#the-django-test-
 client]) in part 5 there is this section of code:

 {{{
 >>> # get a response from '/'
 >>> response = client.get('/')
 >>> # we should expect a 404 from that address
 >>> response.status_code
 404
 >>> # on the other hand we should expect to find something at '/polls/'
 >>> # we'll use 'reverse()' rather than a hardcoded URL
 >>> from django.core.urlresolvers import reverse
 >>> response = client.get(reverse('polls:index'))
 >>> response.status_code
 200
 >>> response.content
 '\n\n\n    <p>No polls are available.</p>\n\n'
 >>> # note - you might get unexpected results if your ``TIME_ZONE``
 >>> # in ``settings.py`` is not correct. If you need to change it,
 >>> # you will also need to restart your shell session
 >>> from polls.models import Poll
 >>> from django.utils import timezone
 >>> # create a Poll and save it
 >>> p = Poll(question="Who is your favorite Beatle?",
 pub_date=timezone.now())
 >>> p.save()
 >>> # check the response once again
 >>> response = client.get('/polls/')
 >>> response.content
 '\n\n\n    <ul>\n    \n        <li><a href="/polls/1/">Who is your
 favorite Beatle?</a></li>\n    \n    </ul>\n\n'
 >>> response.context['latest_poll_list']
 [<Poll: Who is your favorite Beatle?>]
 }}}

 However, when I wrote this test in the console the following error
 occurred:

 {{{
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
 TypeError: 'NoneType' object is not subscriptable
 }}}

 I changed the line
 {{{
 response.context['latest_poll_list']
 }}}
 to
 {{{
 response.context_data['latest_poll_list']
 }}}
 and it worked as intended.

 I'm using Python 2.7 with Django 1.6 in a Windows 7 machine.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22912>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/060.42160c9b1fa05afeb68a51381b205adc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to