no module name error

124 views
Skip to first unread message

Kakar Arunachal Service

unread,
May 18, 2013, 3:42:39 PM5/18/13
to django...@googlegroups.com
I'm practicing from a book Begining django e-commerce and m stuck in one place. My project name is ecomstore, and in it i have two app, one is preview and the other is catalog. In my preview app, there's just html in the templates dir, and thats not the problem, because the result was fine when i ran the server. And then i made a new app, catalog. It has two models, Category and Product. Then to register it with the admin, i made one admin.py file. And there i imported those two module by:
from django.contrib import admin
from django.ecomstore.catalog.models import Category, Product
...and some other forms related import.
Then when i run the server, i get an Import error: No module named catalog.models.
I have installed my app in settings.py.  Hope u guys could solve my problem.

Bill Freeman

unread,
May 18, 2013, 3:54:28 PM5/18/13
to django-users
Unless you actually created your stuff inside your installation of Django (or under some directory named site-packages or dist-packages), which is not recommended, it is unlikely that the place from which you import Category and Products will be named beginning with "django.".

The book may be assuming more background than you have.  If you haven't already done so, doing, one time, the tutorial at docs.djangoproject.com (be sure to do the one for the version of django that you have installed), is very worthwhile.  Things that you may have misinterpreted in the book might then make perfect sense.

And if you're not already facile with python, the tutorial at docs.python.org, again, be sure to do the one for the version of python that you have, is worth doing first of all.

Bill


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kakar Arunachal Service

unread,
May 18, 2013, 4:04:33 PM5/18/13
to django...@googlegroups.com
Oh..m sorry. I mistyped, it was not django.ecomstore.catalog.models, but just, ecomstore.catalog.models import Category, Product. N in the catalog dir, it has __init__.py file, so should have done the problem. N m using sqlite3 so i dnt need adapters too. Pls help.

Bill Freeman

unread,
May 18, 2013, 4:57:07 PM5/18/13
to django-users
Does the ecomstore directory (as well as the catalog dirction) also have an __init__.py file in it?  And is the ecomstore directory in the same directory as manage.py ?

Or is ecomstore the project name, rather than part of an app with extra levels?  (Still needs an __init__.py)   And if so, and if this is a recent Django where settings.py is in a subdirectory (named ecomstore) of the directory containing manage.py (probably also named ecomstore, since startproject creates it that way), which ecomstore contains the catalog directory (It needs to be where settings.py is, since you are qualifying it with the project name)?


On Sat, May 18, 2013 at 4:04 PM, Kakar Arunachal Service <kakararuna...@gmail.com> wrote:
Oh..m sorry. I mistyped, it was not django.ecomstore.catalog.models, but just, ecomstore.catalog.models import Category, Product. N in the catalog dir, it has __init__.py file, so should have done the problem. N m using sqlite3 so i dnt need adapters too. Pls help.

--

Kakar Arunachal Service

unread,
May 18, 2013, 6:59:59 PM5/18/13
to django...@googlegroups.com
ecomstore is the project name. And within it, it has another ecomstore, which has the __init__.py, settings.py, urls.py and wsgi.py. And yes catalog too has the __init__.py file in it, as it was created by the startapp command. The error says, import error: no module named catalog.models in admin.py line 2, which is, from ecomstore.catalog.models import Category Product.

Kakar Arunachal Service

unread,
May 18, 2013, 7:10:09 PM5/18/13
to django...@googlegroups.com
The directory is as follows:
ecomstore
--manage.py
--ecomstore
  __init__.py
     settings.py
     urls.py
     wsgi.py
--preview
 __init__.py
 models.py
 views.py
 test.py
--templates
 --tags
   navigation.html
 base.html
 catalog.html
 index.html
--static
 css.css
--catalog
 __init__.py
 admin.py
 forms.py
 models.py
 tests.py
 views.py

Bill Freeman

unread,
May 18, 2013, 7:10:21 PM5/18/13
to django-users
Yes, but of which directory is the catalog directory a sub-directory?  The upper ecomstore (which contains manage.py) or the lower ecomstore (which contains settings.py)?  Or is it somewhere else entirely?



On Sat, May 18, 2013 at 6:59 PM, Kakar Arunachal Service <kakararuna...@gmail.com> wrote:
ecomstore is the project name. And within it, it has another ecomstore, which has the __init__.py, settings.py, urls.py and wsgi.py. And yes catalog too has the __init__.py file in it, as it was created by the startapp command. The error says, import error: no module named catalog.models in admin.py line 2, which is, from ecomstore.catalog.models import Category Product.

kakararunachalservice

unread,
May 18, 2013, 7:31:35 PM5/18/13
to django...@googlegroups.com

Its in the upper directory, i.e. where the manage.py is.



Sent from Samsung tablet

Bill Freeman

unread,
May 18, 2013, 7:44:03 PM5/18/13
to django-users
Can you run:

   python manage.py shell

?  If you already have an error, try again with the 'ecomstore.catalog', line commented out in settings.py

If shell runs without an error and gives you a python prompt, try the following, in sequence until you get an error:

  >>> import ecomstore
  >>> import ecomstore.catalog
  >>> import ecomstore.catalog.models
  >>> dir(import.ecomstore.models)

If you make it this far, are Product and Category in the list?
If you got an error, at what point?


--

Bill Freeman

unread,
May 18, 2013, 7:53:41 PM5/18/13
to django-users
Ok.  If catalog is in the upper directory, take the leading "ecomstore." off of the import statement.  Also remove it from the entry in INSTALLED_APPS.

Alternatively, move the catalog directory (will all of its contents), into the lower directory. If you are at a unix or mac os shell prompt the 'mv' command will do this for you.  If you are on Windows or in a GUI drag and drop may work, but you're on your own to know how to do it.

Things in the upper directory are directly available for import, without prefixing them with the project name.  That whole directory is on sys.path (as "") because that was the current directory when you typed "python manage.py ...".  The name of this directory actually doesn't matter to Django and Python.  The lower ecomstore is a python package (directory with an __init__.py) in the upper directory, so *THAT* package can be imported with:

   import ecomstore

and things inside that package can be imported by prefixing its name to theirs (ecomstore.settings, ecomstore.url, ecomstore.wsgi, and, if you move the catalog package there, ecomstore.catalog).

Kakar Arunachal Service

unread,
May 18, 2013, 8:05:33 PM5/18/13
to django...@googlegroups.com
Ok i removed ecomstore from,
from ecomstore.catalog.models import Product, Category
to
from catalog.models import Product, Category
And i think it worked fine. But now again it gives an error:
ImproperlyConfigured at/catalog - 'ProductAdmin.exclude' refers to field 'created_at' that is missing from the form.

Kakar Arunachal Service

unread,
May 18, 2013, 8:07:02 PM5/18/13
to django...@googlegroups.com
And by the way thanks for being patience with me!

Bill Freeman

unread,
May 18, 2013, 10:59:35 PM5/18/13
to django-users
Since I'm unfamiliar with the book, I don't know about the 'created_at' field, which must be specific to the book's app design.

Try commenting out the reference to 'created_at' in admin.py and see if you get further.  If so, then try to be sure that you are following the book in order, and that there aren't a set of changes that you need to make together, of which you have only made some.  Try to be sure that you understand each change the book makes, and read ahead before implementing changes.

It's past my bedtime here, and I don't expect to be on line tomorrow.  Good luck.  Someone else may step in to help, or if you're still having trouble on Monday I'll try to find some more time.




On Sat, May 18, 2013 at 8:07 PM, Kakar Arunachal Service <kakararuna...@gmail.com> wrote:
And by the way thanks for being patience with me!

--
Reply all
Reply to author
Forward
0 new messages