姜戈 + Eclipse、shell 问题
我正在使用 pydev 在 Eclipse 中使用 Django。我正在按照此处的教程(http://docs.djangoproject.com/en/dev/intro/tutorial01/)制作一个简单的民意调查应用程序。在示例中,当他们运行 shell 时,他们能够执行此操作:
from polls.models import Poll, Choice
但是,由于某种原因,我无法执行此操作。为了让它发挥作用,我必须这样做:
from projectname.polls.models import Poll, Choice
知道为什么吗?这是日食的事情吗?我的settings.py 中的某个路径是否错误?谢谢!
I'm using pydev to use Django in Eclipse. I'm following the tutorial here (http://docs.djangoproject.com/en/dev/intro/tutorial01/), making a simple poll application. In the example when they run the shell they are able to do this:
from polls.models import Poll, Choice
however, for some reason, I'm not able to do this. In order for it to work, I have to do this:
from projectname.polls.models import Poll, Choice
Any idea why that is? Is it an eclipse thing? Is some path wrong somewhere in my settings.py? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用 PyDev。查看您的 PYTHONPATH 的结构...
(在包资源管理器 > 属性 > Pydev - PYTHONPATH 中右键单击您的项目。
如果您的项目设置为
并且您的 PYTHONPATH 指向
project_root
,那么您必须将 Poll 类引用为projectname.polls.models.Poll
但是,如果将 PYTHONPATH 设置为projectname
,则可以将其引用为 <代码>polls.models.Poll。I'm assuming that you're using PyDev. See how your PYTHONPATH is structured...
(right click on your project in package explorer > properties > Pydev - PYTHONPATH.
If your project is set up as
and if your PYTHONPATH points to
project_root
, then you'll have to refer to Poll class asprojectname.polls.models.Poll
. However, if you set the PYTHONPATH toprojectname
, you can refer it to it aspolls.models.Poll
.