Your Django 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 When I descended into the directory and tried to start the development server, I received the following garbage:

$ ./ runserver
Traceback (most recent call last):
  File "./", line 11, in 
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/", line 436, in execute_manager
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/", 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/", line 35, in import_module
ImportError: No module named

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 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