2

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

1 Answer 1

4

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer you are right but when I write only tryserver.settings or full path it gives ImportError: Could not import settings 'tryserver.settings' (Is it on sys.path?): No module named tryserver.settings . How can I correct this ?
They want to add 'C:/DjangoProjects' to sys.path. At the moment they are possibly only adding 'C:/DjangoProjects/tryserver'. That or don't have 'tryserver.' in DJANGO_SETTINGS_MODULE and leave it at 'settings'. Easier to use long form and add both directories to sys.path.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.