我现在面临两天的问题,但我无法得到任何有效的答案 我有一个名为“ekz”的项目,其中有一个名为“welcome”的应用程序,我需要使用apache + wsgi执行项目(我正在使用osx yosemite)。当我使用“manage.py runserver”运行项目时,它可以正常运行,但是当我使用apache 运行它时,它会给我错误“没有名为ekz的模块.settings “这是来自apache日志的完整跟踪:
mod_wsgi (pid=29210): Target WSGI script '/Users/s2labs/Desktop/ekz/ekz/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=29210): Exception occurred processing WSGI script '/Users/s2labs/Desktop/ekz/ekz/wsgi.py'.
Traceback (most recent call last):
File "/Users/s2labs/Desktop/ekz/ekz/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named ekz.settings
这是 wsgi.py 文件,我没有修改它,它是在我使用pycharm创建项目时创建的:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ekz.settings")
application = get_wsgi_application()
以下是httpd.conf文件的配置,我跟着docs执行此操作:
Alias /static/ /Users/s2labs/Desktop/ekz/welcome/static/
<Directory /Users/s2labs/Desktop/ekz/welcome/static>
Require all granted
</Directory>
WSGIScriptAlias / /Users/s2labs/Desktop/ekz/ekz/wsgi.py
WSGIPythonPath /Users/s2labs/Desktop/ekz:/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages
<Directory /Users/s2labs/Desktop/ekz/ekz>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
非常感谢您的帮助,谢谢。
答案 0 :(得分:0)
我希望这有助于有人面对这个问题。好吧,我所做的是为python3安装wsgi,并使apache用户(www-data)成为我网站目录的所有者及其所有内容,并且工作得很好。