开发者

Unable to access project API in Django in tutorial

开发者 https://www.devze.com 2023-03-25 00:10 出处:网络
I was going through this tutorial in order to learn how Django works: https://docs.djangoproject.com/en/dev/intro/tutorial01/

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消