Your Django manage.py ImportError May be a Syntax Problem

Posted on in Programming

Django LogoBackground: While cleaning up my development directory the other day, I renamed one of my Django project directories to the domain name of the site. For the sake of argument, we'll call it django.slaptijack.com. When I descended into the directory and tried to start the development server, I received the following garbage:

$ ./manage.py runserver
Traceback (most recent call last):
  File "./manage.py", line 11, in 
    execute_manager(settings)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/__init__.py", line 436, in execute_manager
    setup_environ(settings_mod)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/__init__.py", line 419, in setup_environ
    project_module = import_module(project_name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named django.slaptijack.com

If you're like me, this probably shocked the heck out of you. My first thought was that there was some setting somewhere that controlled the name of the project or the primary project module or something. The answer was pretty easy, though.

Django assumes the top-level directory (the one with manage.py) is the primary module. The rule is that Python module names can only consist of letters, numbers, and underscores. This is pretty obvious when you think about how you can invoke methods of modules using dot notation. By replacing my dots with underscores in the directory name, I was able to successfully start up the development server.

My Bookshelf

Reading Now

Other Stuff