I have been trying to get an application written in Django working with Apache 2.2 and mod_wsgi with Django 1.3 and Python 2.7.2 - but it is not working at all. I have been working on for some time too - and it is working on dev-server perfectly. But I am unable to put in the production env (apahce).
My Apache Error logs shows the following:
[error] ['C:\\\\Python27\\\\lib\\\\site-packages\\\\django_tinymce-1.5.1a2-py2.7.egg', 'C:\\\\windows\\\\system32\\\\python27.zip', 'C:\\\\Python27\\\\Lib', 'C:\\\\Python27\\\\DLLs', 'C:\\\\Python27\\\\Lib\\\\lib-tk', 'C:\\\\Apache Software Foundation\\\\Apache2.2', 'C:\\\\Apache Software Foundation\\\\Apache2.2\\\\bin', 'C:\\\\Python27', 'C:\\\\Python27\\\\lib\\\\site-packages', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\PIL', 'C:/wsgi_app/django.wsgi', 'path4', 'C:/workspace/MB/src/', 'C:/Django-1.3']
[Wed Aug 24 10:24:07 2011] [error] [开发者_如何学Cclient 127.0.0.1] mod_wsgi (pid=7608): Exception occurred processing WSGI script 'C:/wsgi_app/django.wsgi'............
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] return self.format('D, j M Y H:i:s O')
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\dateformat.py", line 30, in format
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] pieces.append(force_unicode(getattr(self, piece)()))
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\encoding.py", line 71, in force_unicode
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] s = unicode(s)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\functional.py", line 206, in __unicode_cast
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] return self.__func(*self.__args, **self.__kw)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\__init__.py", line 81, in ugettext
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] return _trans.ugettext(message)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 286, in ugettext
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] return do_translate(message, 'ugettext')
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 276, in do_translate
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] _default = translation(settings.LANGUAGE_CODE)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 185, in translation
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] default_translation = _fetch(settings.LANGUAGE_CODE)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 162, in _fetch
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] app = import_module(appname)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] __import__(name)
[Wed Aug 24 10:24:07 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named IWorks
The following is present in django.wsgi
import os
import sys
path = 'C:/wsgi_app/django.wsgi'
if path not in sys.path:
sys.path.append(path)
path2 = 'C:/workspace/MB/src/'
if path2 not in sys.path:
sys.path.append(path2)
os.environ['DJANGO_SETTINGS_MODULE'] = 'MB.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
print >> sys.stderr, sys.path
And Apache Configs says :
WSGIScriptAlias / "C:/wsgi_app/django.wsgi"
<Directory "C:/wsgi_app/">
Allow from all
</Directory>
I am not able to understand why apache is looking for the module in site-packages.It is present in C:/workspace/MB/src/MB/IWorks? Please advise.
So an answer from both my comments as the OP hasn't replied i'll just assume one or the other will help.
Graham Dumpleton suggested in the comments that this one should be the fix:
add the following to the .wsgi file:
path3 = 'C:/workspace/MB/src/MB/'
if path3 not in sys.path:
sys.path.append(path3)
I don't develop python on windows but I think the paths should be written 'C:\\workspace\\MB\\src\\'
not like 'C:/workspace/MB/src/'
(from the django docs which aren't always correct.)
Let me know if this did/didn't help.
精彩评论