不确定出了什么问题。当我使用
在本地计算机上运行时 python manage.py runserver
一切都好。但是当在Openshift上运行时,我得到了500个内部服务器错误。
rhc tail -a maid
显示
==> app-root/logs/python.log <==
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] File "/var/lib/openshift/56f1365889f5cf9b07000054/python/virtenv/lib/python2.7/site-packages/Django-1.9.2-py2.7.egg/django/__init__.py", line 18, in setup
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] apps.populate(settings.INSTALLED_APPS)
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] File "/var/lib/openshift/56f1365889f5cf9b07000054/python/virtenv/lib/python2.7/site-packages/Django-1.9.2-py2.7.egg/django/apps/registry.py", line 85, in populate
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] app_config = AppConfig.create(entry)
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] File "/var/lib/openshift/56f1365889f5cf9b07000054/python/virtenv/lib/python2.7/site-packages/Django-1.9.2-py2.7.egg/django/apps/config.py", line 116, in create
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] mod = import_module(mod_path)
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] File "/opt/rh/python27/root/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] __import__(name)
[Fri Mar 25 17:40:12 2016] [error] [client 127.3.227.129] ImportError: No module named mblog.apps
82.28.196.48 - - [25/Mar/2016:13:40:11 -0400] "GET / HTTP/1.1" 500 617 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4"
我已经将mblog / init .py定义为
default_app_config = 'mblog.apps.MblogConfig'
和apps.py为
from __future__ import unicode_literals
from django.apps import AppConfig
class MblogConfig(AppConfig):
name = 'mblog'
def ready(self):
from .defaults import *
wsgi / application有以下设置:
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'MaidProject', 'mblog'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'MaidProject.lineblog.settings'
文件结构为:
MaidProject
- __init__.py
- lineblog
- __init__.py
- settings.py
- urls.py
- wsgi.py
- manage.py
- mblog
- __init__.py
- admin.py
- apps.py
- default.py
- ...
- locale (dir)
- templates (dir)
当我推送我以前的Django 1.6时,我没有遇到这个问题,但现在正在使用新的应用程序来处理Django 1.9。尝试一些事情,不要在哪里。非常感谢任何指针。错误在Openshift上,但在本地计算机上运行时,没有问题。我一定在某个地方做错了什么,但现在花了几天时间,但仍然没有在哪里。真的很沮丧。 提前谢谢。
答案 0 :(得分:0)
感谢格雷厄姆指出PYTHONPATH。这解决了这个问题。事实证明,我设置的路径不正确并且从
更改sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'MaidProject', 'mblog'))
以下做了诀窍:
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi'))
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'MaidProject'))