Opened 13 years ago

Closed 13 years ago

#17104 closed Bug (worksforme)

from polls.models import Choice in admin.py

Reported by: rodrigodelimavieira@… Owned by: RodrigoJimmy
Component: Documentation Version: 1.3
Severity: Normal Keywords: tutorial, error
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In "Adding related objects" at https://docs.djangoproject.com/en/1.3/intro/tutorial02/ we have the code:

from polls.models import Choice

but in my app, it isn't works for me, because admin.py is in poll folder, so that, the code below works for me:

from models import Choice

Change History (1)

comment:1 by Carl Meyer, 13 years ago

Resolution: worksforme
Status: newclosed

from polls.models import Choice does work if you've followed the tutorial up to that point, and you're running python manage.py runserver, because the directory containing manage.py is added to sys.path. So you must be doing something else different from the tutorial.

Using from polls.models import Choice, as the tutorial does, can cause problems when deploying to production, because it often requires adding two overlapping paths to sys.path in your webserver configuration. This issue has already been extensively discussed and is fixed in trunk (r16964).

Using a relative import instead of an absolute one (as you are doing) is also fine, but you should really make the relative import explicit instead of implicit by using from .models import Choice.

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