Opened 7 years ago

Closed 7 years ago

#17104 closed Bug (worksforme)

from polls.models import Choice in

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


In "Adding related objects" at we have the code:

from polls.models import Choice

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

from models import Choice

Change History (1)

comment:1 Changed 7 years ago by Carl Meyer

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 runserver, because the directory containing 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