繁体   English   中英

带有mod_wsgi的Apache发出有关Django中数据库的错误

[英]Apache with mod_wsgi emitting error concerning database in django

首先,我已经搜索并尝试了有关该主题的众多答案,但似乎没有帮助。 由于某些原因,我在Apache和django中遇到了一个奇怪的错误。 这是我的设置:我正在运行Mac OS X El Capitan,我正在使用OS Apache 2.4,并且已经安装了mod_wsgi扩展。 我可以使用“ runserver”命令通过终端运行django,而不会出现任何问题。 我也在虚拟环境中运行django项目。 我安装了python3,所以我不必使用操作系统python2。因此,虚拟环境基于python3。按照django文档中的建议,我的django项目使用mysqlclient驱动程序连接到mysql。 我的Django版本是1.9。 我已经使用以下vhost配置将apache vhost文件配置为服务于django项目:

<VirtualHost *:80>

ServerName simplesurvey.proj
ServerAdmin admin@simplesurvey.proj

Alias /static /Users/UncharteD/Sites/project/survey/static/
<Directory /Users/UncharteD/Sites/project/survey/static/>
    Require all granted
</Directory>

<Directory /Users/UncharteD/Sites/project/surveyproject/>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess simplesurvey python-path=/Users/UncharteD/Sites/project/:/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages
WSGIProcessGroup simplesurvey
WSGIScriptAlias / /Users/UncharteD/Sites/project/surveyproject/wsgi.py

我的网络浏览器显示500错误状态。 我已将simplesurvey.proj添加为主机文件的条目。 正是以下浏览器消息:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

我检查了我的Apache错误日志,它包含以下内容:

完整的Apache错误日志

我认为最重要的一点是堆栈跟踪。 当命令行版本可以完美地完成所有操作时,为什么无法加载模块? 以下是日志中的内容:

   [Thu May 05 18:31:52.828568 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] mod_wsgi (pid=64376): Target WSGI script '/Users/UncharteD/Sites/project/surveyproject/wsgi.py' cannot be loaded as Python module.
[Thu May 05 18:31:52.828660 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] mod_wsgi (pid=64376): Exception occurred processing WSGI script '/Users/UncharteD/Sites/project/surveyproject/wsgi.py'.
[Thu May 05 18:31:52.828681 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] Traceback (most recent call last):
[Thu May 05 18:31:52.828701 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/Sites/project/surveyproject/wsgi.py", line 16, in <module>
[Thu May 05 18:31:52.828779 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     application = get_wsgi_application()
[Thu May 05 18:31:52.828792 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu May 05 18:31:52.828875 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     django.setup()
[Thu May 05 18:31:52.828898 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
[Thu May 05 18:31:52.828973 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     apps.populate(settings.INSTALLED_APPS)
[Thu May 05 18:31:52.828991 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
[Thu May 05 18:31:52.829136 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     app_config.import_models(all_models)
[Thu May 05 18:31:52.829150 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
[Thu May 05 18:31:52.829224 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     self.models_module = import_module(models_module_name)
[Thu May 05 18:31:52.829234 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu May 05 18:31:52.829309 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     __import__(name)
[Thu May 05 18:31:52.829320 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/Sites/project/survey/models.py", line 22, in <module>
[Thu May 05 18:31:52.829432 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     class Genre(models.Model):
[Thu May 05 18:31:52.829441 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/models/base.py", line 108, in __new__
[Thu May 05 18:31:52.829807 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     new_class.add_to_class('_meta', Options(meta, app_label))
[Thu May 05 18:31:52.829817 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/models/base.py", line 307, in add_to_class
[Thu May 05 18:31:52.829844 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     value.contribute_to_class(cls, name)
[Thu May 05 18:31:52.829852 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/models/options.py", line 263, in contribute_to_class
[Thu May 05 18:31:52.830098 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Thu May 05 18:31:52.830109 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/__init__.py", line 36, in __getattr__
[Thu May 05 18:31:52.830150 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Thu May 05 18:31:52.830158 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/utils.py", line 212, in __getitem__
[Thu May 05 18:31:52.830249 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     backend = load_backend(db['ENGINE'])
[Thu May 05 18:31:52.830258 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/utils.py", line 116, in load_backend
[Thu May 05 18:31:52.830271 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     return import_module('%s.base' % backend_name)
[Thu May 05 18:31:52.830279 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu May 05 18:31:52.830291 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     __import__(name)
[Thu May 05 18:31:52.830297 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]   File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
[Thu May 05 18:31:52.830400 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0]     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
[Thu May 05 18:31:52.830420 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql

任何有关如何解决此问题的帮助将不胜感激。 谢谢

也许是权限问题?

Apache拥有自己的用户,因此该用户可能无权访问您的virtualenv路径,特别是因为它位于用户文件夹中。 通常可以通过将apache用户添加到您的用户组来解决。

至少我知道这就是Linux的工作方式,我猜想它与Mac差不多吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM