1

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!

9
  • What do you mean by 'not able to do this'? Does it give an error or what? Commented Nov 16, 2010 at 17:18
  • 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 Commented Nov 16, 2010 at 17:19
  • 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? Commented Nov 16, 2010 at 17:20
  • 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? Commented Nov 16, 2010 at 17:23
  • 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 Commented Nov 16, 2010 at 17:29

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.