I can't seem to understand why django/apache refuses to load DJANGO_SETTINGS_MODULE inspite of it being declared! I checked that the environmental variable is loaded through python, and manage.py can create a run server without any errors about the settings.
我似乎无法理解为什么django / apache拒绝加载DJANGO_SETTINGS_MODULE,尽管它被声明!我检查了环境变量是通过python加载的,manage.py可以创建一个运行服务器而没有任何关于设置的错误。
echo $DJANGO_SETTINGS_MODULE >>> harshp.settings.production
Apache error log
Apache错误日志
AH02282: No slotmem from mod_heartmonitor
AH00489: Apache/2.4.12 (Unix) OpenSSL/1.0.1k mod_wsgi/3.5 Python/2.7.6 configured -- resuming normal operations
AH00094: Command line: '/opt/bitnami/apache2/bin/httpd -f /opt/bitnami/apache2/conf/httpd.conf'
mod_wsgi (pid=7056): Exception occurred processing WSGI script '/opt/bitnami/apps/django/django_projects/harshp.com/harshp/wsgi.py'.
Traceback (most recent call last):
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
self.load_middleware()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 49, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/opt/bitnami/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting MIDDLEWARE_CLASSES, but settings are not configured.
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.~
Apache config
Apache配置
WSGIScriptAlias / /opt/bitnami/apps/django/django_projects/harshp.com/harshp.wsgi
WSGIPythonPath /opt/bitnami/apps/django/django_projects/harshp.com
<Directory /opt/bitnami/apps/django/django_projects/harshp.com/>
Require all granted
</Directory>
wsgi.py
wsgi.py
sys.path.append('/opt/bitnami/apps')
sys.path.append('/opt/bitnami/apps/django/django_projects/harshp.com')
*** edit *** SETTINGS was typed as SETTNGS only on SO
os.environ['DJANGO_SETTINGS_MODULE']='harshp.settings.production'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
httpd-app.conf
的httpd-app.conf
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
WSGIScriptAlias / '/opt/bitnami/apps/django/django_projects/harshp.com/harshp/wsgi.py'
<Directory "/opt/bitnami/apps/django/django_projects/harshp.com/harshp/">
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
1 个解决方案
#1
1
bitnami developer here. I think you have a typo, at least in the code you are pasting:
bitnami开发者在这里。我认为你有一个拼写错误,至少在你粘贴的代码中:
os.environ['DJANGO_SETTNGS_MODULE']='harshp.settings.production'
Can you try to change it from SETTNGS to SETTINGS?
你能尝试将它从SETTNGS更改为SETTINGS吗?
#1
1
bitnami developer here. I think you have a typo, at least in the code you are pasting:
bitnami开发者在这里。我认为你有一个拼写错误,至少在你粘贴的代码中:
os.environ['DJANGO_SETTNGS_MODULE']='harshp.settings.production'
Can you try to change it from SETTNGS to SETTINGS?
你能尝试将它从SETTNGS更改为SETTINGS吗?