Sykes
Sykes

Reputation: 9

Django application database error: No module named

I was trying to connect my database application to project in django. Succeded on connecting psycopg and database. Then I started to build application for it by

python manage.py startapp books

and wrote some code in models.py.

But when I tried to put application in INSTALLED_APPS, it caused on error.

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'tut1.books',
# Uncomment the next line to enable the admin:
 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',

So, I'm in project's folder and type in Command Line:

%>python manage.py syncdb
ImportError: No module named 'tut1.books'

If I remove my app from INSTALLED_APPS, everything goes fine. I suspect, there gotta be different syntax for linking application.

Tried to change 'tut1.books' to just 'books'. Causes another error.

%>python manage.py syncdb
AttributeError:'module' object has no attribute 'URLFIELD'

Files and folders in project /tut1/

   manage.py
   views.py
   /tut1/
   /templates/
   /books/

Files in /books/

   __init__.py
   modules.py
   views.py
   tests.py

Files in /tut1/tut1/

   __init__.py
   settings.py
   urls.py
   views.py
   wsgi.py

init.py is empty by default.

Checked PYTHONPATH for this project. Nothing odd...

>>> import sys
>>> for i in sys.path:
      print(i)


C:\study\django\tut1
C:\Python33\Lib\idlelib
C:\Python33\lib\site-packages\setuptools-1.1.6-py3.3.egg
C:\Python33\python33.zip
C:\Python33\DLLs
C:\Python33\lib
C:\Python33
C:\Python33\lib\site-packages

Upvotes: 0

Views: 698

Answers (2)

akiniwa
akiniwa

Reputation: 617

It can be a problem with models.py. You seem to write code as follows.

foo = models.URLFIELD()

"models" module has no URLFIELD().

You should change it to URLField().

Upvotes: 1

Randall Hunt
Randall Hunt

Reputation: 12572

You'll need to add an __init__.py file (it can be empty) to the folder tut1.books before python can import it. See this answer: What is __init__.py for?

Upvotes: 0

Related Questions