我正在尝试在Apache上部署Django项目,在Windows 10中部署wsgi_mod。到目前为止我做了什么:
1。在Apache conf文件夹的httpd.conf中添加了以下内容
WSGIScriptAlias / "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py"
WSGIPythonPath "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project;C:/Bitnami/djangostack-1.10.1-0/python/Lib/site-packages"
<Directory "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
2。以下是我的wsgi.py文件的内容:
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "egeirn.settings")
application = get_wsgi_application()
当我启动Apache服务器时,它在日志文件中出现以下错误:
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] mod_wsgi (pid=916): Target WSGI script 'C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py' cannot be loaded as Python module., referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] mod_wsgi (pid=916): Exception occurred processing WSGI script 'C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py'., referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] Traceback (most recent call last):, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py", line 18, in <module>, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] application = get_wsgi_application(), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\core\\wsgi.py", line 13, in get_wsgi_application, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] django.setup(set_prefix=False), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\__init__.py", line 22, in setup, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\conf\\__init__.py", line 53, in __getattr__, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] self._setup(name), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\conf\\__init__.py", line 41, in _setup, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] self._wrapped = Settings(settings_module), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\conf\\__init__.py", line 116, in __init__, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] raise ImproperlyConfigured("The SECRET_KEY setting must not be empty."), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] ImproperlyConfigured: The SECRET_KEY setting must not be empty., referer: http://localhost:82/
我正在使用django-environ来读取.env文件并在环境变量中保留配置。虽然我在SECRET_KEY
文件中有base.py
我在base.py
文件中使用了这个:
import environ
# three folder back (/project/egeirn/settings/ - 3 = /)
root = environ.Path(__file__) - 3
# set default values and casting
env = environ.Env(DEBUG=(bool, False),)
# reading .env file
environ.Env.read_env(os.path.join(BASE_DIR, '../../config/.env'))
SITE_ROOT = root()
# Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')
这是我的.env
文件:
SECRET_KEY=<MY_SECRET_KEY_HERE>
请告诉我这里做错了什么,怎么看不到SECRET_KEY
?
由于