-1

Very new to Django so please bear with me. Following along with the Django polls project using The Django Book's classes (Publisher, Author, Book). I've been stuck on importing my models in the shell.

The app name is General and the project name is mysite

The error:

>>> from General.models import Publisher, Author, Book

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from General.models import Publisher, Author, Book
ImportError: No module named General.models
>>> 

My folders:

C:\
BookShelf/
  sqlite3.db
  mysite/
    mysite
    media
    manage.py
    General/
       _init_.py
       _init_.pyc
       models.py
       models.pyc
       tests.py
       views.py

if this helps:

>>> import sys
>>> print sys.path
['', 'C:\\Python27\\Lib\\idlelib', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', 'C
:\\Python27\\Lib\\lib-tk', 'C:\\BookShelf\\mysite\\General\\models.py', 'C:\\WIN
DOWS\\system32\\python27.zip', 'C:\\Python27\\"C:\\BookShelf\\mysite\\General\\m
odels.py"', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27', 'C:\\Python27\\lib\\s
ite-packages', 'C:\\Python27\\lib\\site-packages\\PIL']  
>>>   

I've tried 'from mysite.General.models' with no success as well.

Thanks in advance!

2 Answers2

0

C:\BookShelf\mysite should be in your PYTHONPATH. Try following -

cd C:\BookShelf\mysite
python manage.py shell
from General.models import Publisher, Author, Book

You should always use python manage.py shell to open a python shell for django projects. manage.py puts your project’s package on sys.path.

pankaj28843
  • 2,458
  • 17
  • 34
0

Your _init_.py files should be named __init__.py - two underscores each side.

Note that it's probably not good practice to call your app General - you should use all lower case names for packages.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895