簡體   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