我在使用python 2.7的可伸縮OpenShift平臺上運行Django(1.8.7)應用程序時出現問題。由於某些原因,它無法獲取環境變量OPENSHIFT_POSTGRESQL_DB_URL
的信息。嗯,這是錯誤:在OpenShift可伸縮應用程序上運行Django 1.8
mod_wsgi (pid=69306): Target WSGI script '/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module.
mod_wsgi (pid=69306): Exception occurred processing WSGI script '/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/application'.
Traceback (most recent call last):
File "/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/application", line 21, in <module>
application = get_wsgi_application()
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/rh/python27/root/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/bet/controller/settings.py", line 59, in <module>
url = urlparse.urlparse(os.environ.get('OPENSHIFT_POSTGRESQL_DB_URL'))
File "/opt/rh/python27/root/usr/lib64/python2.7/urlparse.py", line 143, in urlparse
tuple = urlsplit(url, scheme, allow_fragments)
File "/opt/rh/python27/root/usr/lib64/python2.7/urlparse.py", line 182, in urlsplit
i = url.find(':')
AttributeError: 'NoneType' object has no attribute 'find'
這是我如何使用settings.py變量,以前的工作:
import urlparse
DATABASES = {}
if ON_OPENSHIFT:
url = urlparse.urlparse(os.environ.get('OPENSHIFT_POSTGRESQL_DB_URL'))
DATABASES['default'] = {
'ENGINE' : 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['OPENSHIFT_APP_NAME'],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
}
,這是我application
文件:
#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'bet'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'controller.settings'
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except:
pass
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
如果我通過rhc ssh bet
登錄到我的應用程序並嘗試打印變量,它工作正常:
echo $OPENSHIFT_POSTGRESQL_DB_URL
postgresql://admin:password-mynick.rhcloud.com:port/
和想法我錯過了什麼。我看起來here沒有運氣。
注意:我的應用程序被命名爲bet
。但是,由於我將它移動到可伸縮應用程序,我在openshift中創建了abet
應用程序。我保留wsgi
文件夾中的應用程序名稱bet
。可能會導致一些問題?
我已經回答了我的問題。但是,謝謝。 – Lucas03