Opened 2 years ago

Closed 2 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

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.