我想与Apache 2
和Django 2.0.
合作
所以我修改了/etc/apache2/sites-sites-available/000-default.conf和/home/duen/django/mysite/wsgi.py。
python = 3.4.2
django = 2.0
apache = 2.4.10
device = raspbarry pi 3 model B
os = OpenMediaVault 3.0.88
000-default.conf
<VirtualHost *: 80>
ServerAdmin sin12070@gmail.com
DocumentRoot / var / www / html
ErrorLog $ {APACHE_LOG_DIR} /error.log
CustomLog $ {APACHE_LOG_DIR} /access.log combined
WSGIDaemonProcess mysite python-path = / home / duen / django / mysite: /home/duen/django/venv/lib/python3.4/site-packages
WSGIScriptAlias / /home/duen/django/mysite/wsgi.py
<Directory / home / duen / django / mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
wsgi.py
import os
import sys
sys.path.append ('/ hoem / duen / django')
sys.path.append ('/ hoem / duen / django / mysite')
sys.path.append ('/ home / duen / django / venv / lib / python3.4 / site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault ("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application ()
但是,当我访问网页时,我可以在error.log中看到此错误。
error.log中
mod_wsgi (pid=9040): Exception occurred processing WSGI script '/home/duen/django/mysite/wsgi.py'.
Traceback (most recent call last)
File "/home/duen/django/mysite/wsgi.py", line 20, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python3.4/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'mysite'
答案 0 :(得分:0)
您没有告诉mod_wsgi在您设置的守护程序进程组中运行WSGI应用程序。变化:
echo'<img src = "directory/images/girl-g2109_5_720.jpg">';
为:
WSGIDaemonProcess mysite python-path=/home/duen/django/mysite:/home/duen/django/venv/lib/python3.4/site-packages
WSGIScriptAlias / /home/duen/django/mysite/wsgi.py
另请注意,我更改为使用WSGIDaemonProcess mysite python-path=/home/duen/django/mysite \
python-home=/home/duen/django/venv
WSGIScriptAlias / /home/duen/django/mysite/wsgi.py \
process-group=mysite application-group=%{GLOBAL}
,这是指定虚拟环境位置的推荐方式。
有关如何正确设置虚拟环境的详细信息,请参阅: