Reputation: 1153
I'm learning Django by reading this book religiously. I'm on chapter 5 : Models, and everything worked fine (in InteractiveConsole) until I reached Basic Data Access.
epqrs@epqrs:~/webapps/djcode/mysite$ pwd
/home/epqrs/webapps/djcode/mysite
epqrs@epqrs:~/webapps/djcode/mysite$ python ../manage.py shell
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from books.models import Publisher
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named books.models
>>> import sys
>>> sys.path
['/home/epqrs/webapps/djcode', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
>>>
I don't get why I get ImportError: No module named books.models.
books directory lies under the current directory mysite (/home/epqrs/webapps/djcode/mysite/books).
Upvotes: 3
Views: 7006
Reputation: 146
I've had to change it to this:
from books.models import Publisher, Author, Book
So basically, I had to take the mysite
portion out.
Also, change installed apps from 'mysite.books'
to just 'books'
I hope it helps
Upvotes: 13
Reputation: 1153
I had to do
from mysite.books.models import Publisher
to make it work.
Upvotes: 1