我试图在 OpenShift 上部署我的 django 应用程序,但出了点问题,我不知道如何解决这个问题。
rhc tail -a myproject 的结果: (并且站点页面显示 500 Internal Server Error)
[Sat Feb 27 07:23:32 2016] [notice] SIGHUP received. Attempting to restart
[Sat Feb 27 07:23:32 2016] [notice] Digest: generating secret for digest authentication ...
[Sat Feb 27 07:23:32 2016] [notice] Digest: done
[Sat Feb 27 07:23:32 2016] [notice] Apache/2.2.15 (Unix) mod_wsgi/3.4 Python/3.3.2 configured -- resuming normal operations
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] mod_wsgi (pid=506177): Target WSGI script '/var/lib/openshift/56d067420c1e664f0e0000da/app-root/runtime/repo/wsgi.py' can
not be loaded as Python module.
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] mod_wsgi (pid=506177): Exception occurred processing WSGI script '/var/lib/openshift/56d067420c1e664f0e0000da/app-root/ru
ntime/repo/wsgi.py'.
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] Traceback (most recent call last):
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/app-root/runtime/repo/wsgi.py", line 10, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from myblog.wsgi import application
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/app-root/runtime/repo/myblog/wsgi.py", line 12, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from django.core.wsgi import get_wsgi_application
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/core/wsgi.py
", line 2, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from django.core.handlers.wsgi import WSGIHandler
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/core/handler
s/wsgi.py", line 10, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from django import http
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/http/__init_
_.py", line 2, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from django.http.request import (
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/http/request
.py", line 10, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from django.core import signing
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/core/signing
.py", line 51, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from django.utils.module_loading import import_string
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] File "/var/lib/openshift/56d067420c1e664f0e0000da/python/virtenv/venv/lib64/python3.3/site-packages/django/utils/module
_loading.py", line 67, in <module>
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] from importlib.util import find_spec as importlib_find
[Sat Feb 27 07:25:08 2016] [error] [client 127.5.163.1] ImportError: cannot import name find_spec
1.194.187.34 - - [27/Feb/2016:07:25:08 -0500] "GET / HTTP/1.1" 500 618 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safa
ri/537.36"
这是我第一次在 PaaS 平台 OpenShift 上部署我的应用程序。 在此之前,我只是用centos(python3.5, django 1.9.2)在我的CVM上部署成功。
我的文件是这样放的:
myproject/
+---wsgi/
| +---static/
| +---.gitkeep
+---wsgi.py
+---setup.py
+---.openshift/
+---requirements.txt
+---myblog/
| +----__init__.py
| +----urls.py
| +----settings.py
| +----wsgi.py
+---+blog/
+----__init__.py
+----models.py
+----views.py
+----tests.py
+----migrations
+---__init__.py
我的项目/wsgi.py:
#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
exec(compile(open(virtualenv, 'rb').read(), virtualenv, 'exec'), dict(__file__=virtualenv))
except IOError:
pass
from myblog.wsgi import application
我的项目/我的博客/wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings")
application = get_wsgi_application()
我的Django版本是最新的1.9.2,python 3.3是openshift提供的。
感谢您关注我的问题并帮助我解决问题。
请您参考如下方法:
仅限 Django 1.9 supports Python 3.4 or higher .您的特定错误是由调用 find_spec 引起的 added in Python 3.4 .
您可以降级到 Django 1.8 或选择其他支持 Python 3.4 的 PaaS 提供商。
