views:

37

answers:

3

I just moved a django project to a deployment server from my dev server, and I'm having some issues deploying it. My apache config is as follows:

<Location "/">
        Order allow,deny
        Allow from all
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE project.settings
        PythonDebug On
        PythonPath "['/home/django/'] + sys.path"
</Location>

Django does work, since it renders the Django debug views, but I get the following error:

ImportError at /
No module named app.urls

And here is all the information Django gives me:

Request Method: GET
Request URL: http://myserver.com/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'project.app']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib64/python2.6/site-packages/django/core/handlers/base.py" in get_response
  83.                     request.path_info)
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  218.                     sub_match = pattern.resolve(new_path)
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  216.             for pattern in self.url_patterns:
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
  245.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
  240.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib64/python2.6/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: ImportError at /
Exception Value: No module named app.urls

Any ideas as to why I get an import error?

+1  A: 

Add the project directory to sys.path.

Ignacio Vazquez-Abrams
My project directory was already in sys.path, I also added my app directories to the path and now it works.
hora
A: 

I would recommend to use virtualenv along with mod_python. Some instructions here: http://mydjangoblog.com/2009/03/30/django-mod_python-and-virtualenv/

It has the advantage of solving all your path problems, but also to allow to install extra modules (or even other versions of django) very easily.

Olivier
A: 

My guess is that if you simply change your url configuration to reference "project.app.urls" instead of "app.urls", your problem will be fixed.

It seems that you've listed "project.app" in INSTALLED_APPS in your project's settings.py file, but you've referenced "app.urls" in your urls.py. You need to standardize and either always reference "app", and change your PythonPath to include the project directory, or always reference "project.app".

Joseph Spiros