开发者

Django deployment - can't import app.urls

开发者 https://www.devze.com 2023-01-02 01:31 出处:网络
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:

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 开发者_如何学Pythoninformation 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?


Add the project directory to sys.path.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消