Unable to access project API in Django in tutorial
I was going through this tutorial in order to learn how Django works:
https://docs.djangoproject.com/en/dev/intro/tutorial01/
Now, when I get to the part where you execute python manage.py shell
, I enter the shell and try to run the different commands, I get this:
>>> Poll.objects.all()
Traceback (most recent call last):
File "\", line 1, in \
NameErro开发者_StackOverflow社区r: name 'Poll' is not defined
What am I doing wrong? I re-ran the previous steps as best I could.
You should have imported Poll with from polls.models import Poll
Kamyar is almost right, if you received this error you probably missed the first line of the code, which is
>>> from polls.models import Poll, Choice # Import the model classes we just wrote.
so do that and you should be fine.
精彩评论