处理WSGI脚本 - WAMP Server时发生异常

时间:2013-08-06 10:37:11

标签: python django apache wamp mod-wsgi

在Windows Server 2008 R2 Wamp Machine上安装了Python和Django。一切都很好,除了以前在LAMP机器上的django / python网站的移植版本。

通过Web浏览器访问vhost时出现

500内部服务器错误

我从apache获取此错误日志:

[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] mod_wsgi (pid=1788): Exception occurred processing WSGI script 'C:/Wamp/www/mysite_com/mysite_com.wsgi'.
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 255, in __call__
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]     response = self.get_response(request)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 178, in get_response
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 220, in handle_uncaught_exception
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]     if resolver.urlconf_module is None:
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\core\\urlresolvers.py", line 342, in urlconf_module
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]     self._urlconf_module = import_module(self.urlconf_name)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]   File "C:\\Python27\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1]     __import__(name)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] ImportError: No module named urls

这是我的.wsgi应用:

import os, sys

sys.path.append('c:/Wamp/www/')
os.environ ['DJANGO_SETTINGS_MODULE'] = 'mysite_com.settings'

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

我的apache vhosts

<VirtualHost *:80>
        ServerName mysite.com
        ServerAlias www.mysite.com
        DocumentRoot "C:/Wamp/www/mysite_com/"
        WSGIScriptAlias / "C:/Wamp/www/mysite_com/mysite_com.wsgi"
</VirtualHost>

文件夹结构

   \www
       \mysite_com
                  \__init__.py
                  \settings.py
                  \urls.py
                  \manage.py
                  \mysite_com.wsgi

有什么建议吗? 感谢

1 个答案:

答案 0 :(得分:0)

您将系统路径的站点路径添加错误。在Linux中看到你会在windows中使用正斜杠'/'(你似乎正在使用)反向斜杠'\'。当然,您需要将它们加倍,以便它不会呈现为转义字符串:

sys.path.append('C:\\wamp\\www')

当然,这样会容易得多:

sys.path.append(r'C:\wamp\www')

看看 - 你的服务器可以找到wsgi应用程序,因为你告诉apache在哪里找到它,所以它抱怨它找不到的下一个模块(恰好是urls.py)。我已经在评论中回答,但我想到了为什么你看到特定方式的错误会有所帮助的解释。

P.S。 如果仍然无效,您可能需要将路径附加到实际应用程序:

sys.path.append(r'C:\Wamp\www\mysite_com')