Opened 11 years ago

Closed 11 years ago

#21069 closed Bug (invalid)

Wrong model name imported in the example

Reported by: er.balram.singh1990@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords:
Cc: er.balram.singh1990@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi, I am new to Django and I was learning through documentation. In the part three, in the "Write views that actually do something" section, the model name 'Question' is imported instead of 'Poll', as that is created in previous part 2. This is throwing an exception saying 'Can't import Question Model'.

from django.http import HttpResponse

from polls.models import '''Question'''


def index(request):
    latest_question_list = '''Question'''.objects.order_by('-pub_date')[:5]
    output = ', '.join([p.question_text for p in latest_question_list])
    return HttpResponse(output)

I have tried to replace that with 'Poll' and that worked. So please update the doc if you find the same.

Secondly, in the view's index template, replace the text 'question.question_text' with 'question' and that will work fine.


Attachments (1)

Writing your first Django app, part 3 | Django documentation | Django.html (69.6 KB ) - added by er.balram.singh1990@… 11 years ago.

Download all attachments as: .zip

Change History (2)

comment:1 by Aymeric Augustin, 11 years ago

Resolution: invalid
Status: newclosed

The tutorial for the development version of Django was changed yesterday (Poll => Question). I'm pretty sure the current version is internally consistent, and you ran into trouble only because you had started with the previous version. Thanks for the report and sorry for the inconvenience.

Regarding the template, I don't think the current code is incorrect. {{ question }} works as well, but {{ question.question_text }} is more explicit and doesn't depend on the definition of the text representation of the Question object.

Note: See TracTickets for help on using tickets.
Back to Top