1
votes

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!

1
What do you mean by 'not able to do this'? Does it give an error or what? - user225312
eclipse autocompletes for me, but it won't autocomplete this. If I try to do it anyway it says Traceback (most recent call last): File "<console>", line 1, in <module> ImportError: No module named polls.models - JPC
From which directory are you accessing the project? Are you running the shell from your "projectname" directory? Does it works when you use normal shell? - crodjer
In eclipse, I right click on my project, click on django, then shell with django environment. I'm not sure what directory it's running from. Is there a command to tell? - JPC
I think the problem is that in Eclipse, you make a project and then the first folder it creates in that project is the name of your project, which is redundant...I don't know how to change that though - JPC

1 Answers

5
votes

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

project_root/
+-projectname/
  +-polls/
    +-models.py

and if your PYTHONPATH points to project_root, then you'll have to refer to Poll class as projectname.polls.models.Poll. However, if you set the PYTHONPATH to projectname, you can refer it to it as polls.models.Poll.