尝试通过apache2
配置wsgi
以便为Django项目提供服务时出现一个奇怪的问题。
我的项目是这里实施的一个小待办事项清单。 https://github.com/panospet/toDoList
当apache尝试运行wsgi.py
时,返回此错误:
Traceback (most recent call last):
File "/var/www/toDoList/myToDoList/wsgi.py", line 19, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named myToDoList.settings
我的wsgi.py
文件就像:
import os
import sys
sys.path.append(' /var/www/toDoList')
sys.path.append(' /var/www/toDoList/myToDoList')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myToDoList.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
以及.conf
内的/etc/apache2/sites-enabled
文件:
<VirtualHost *:80>
DocumentRoot "/var/www/toDoList"
ServerName blahblah
WSGIDaemonProcess todolist user=test group=test threads=5
WSGIScriptAlias / /var/www/toDoList/myToDoList/wsgi.py
<Location /todolist>
WSGIProcessGroup todolist
</Location>
<Directory /var/www/toDoList/toDoList>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/toDoList/myToDoList/static/
<Directory /var/www/toDoList/myToDoList/static>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
答案 0 :(得分:1)
删除sys.path.append中的空格
sys.path.append('/var/www/toDoList')
sys.path.append('/var/www/toDoList/myToDoList')
答案 1 :(得分:0)
基于Django documentation您错过了WSGIPythonPath
:
WSGIPythonPath /var/www/toDoList
此行确保您的项目包可在Python路径上导入;换句话说,导入mysit有效。