brsbilgic
brsbilgic

Reputation: 11833

Apache mod-wsgi django problem

I got this error messages while I am trying to deploy my django app under mod-wsgi in Apache.

[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4152): Exception     occurred processing WSGI script 'C:/DjangoProjects/tryserver/Apache/django.wsgi'.
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1] Traceback (most recent call   last):
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 250, in __call__
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]     self.load_middleware()
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-  packages\\django\\core\\handlers\\base.py", line 39, in load_middleware
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\utils\\functional.py", line 276, in __getattr__
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]     self._setup()
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 42, in _setup
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]     self._wrapped = Settings(settings_module)
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 87, in __init__
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\utils\\importlib.py", line 28, in import_module
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1]     raise TypeError("relative imports require the 'package' argument")
[Thu Jun 30 23:03:35 2011] [error] [client 127.0.0.1] TypeError: relative imports require the 'package' argument

This is my django.wsgi and it is in proper location.

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = '../tryserver/tryserver.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

What could be the problem ?

Thanks

Upvotes: 2

Views: 1844

Answers (1)

Donald Stufft
Donald Stufft

Reputation: 1148

Your Problem is:

os.environ['DJANGO_SETTINGS_MODULE'] = '../tryserver/tryserver.settings'

DJANGO_SETTINGS_MODULE needs to be an importable python module that contains your settings. Django is basically going to do import ../tryserver/tryserver.settings with your current django.wsgi

The best fix to get what you are trying to do is to add the tryserver directory to the python path. Assuming your directory layout looks something like:

./
    tryserver/
        tryserver/
            settings.py
    deploy/
        django.wsgi

Then in your django.wsgi you could do something like:

import os
import sys

sys.path = sys.path + ["/PATH/TO/tryserver/"] # The first one

os.environ['DJANGO_SETTINGS_MODULE'] = 'tryserver.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Upvotes: 4

Related Questions