chachan
chachan

Reputation: 2462

Could not import settings in Django over OpenShift

I'm testing OpenShift with Django/Python 2.7 and I'm getting this:

127.5.232.1 - - [2013-06-28 17:01:37] "GET / HTTP/1.1" 500 161 0.013770
Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/gevent/pywsgi.py", line 438, in handle_one_response
    self.run_application()
  File "build/bdist.linux-x86_64/egg/gevent/pywsgi.py", line 424, in run_application
    self.result = self.application(self.environ, self.start_response)
  File "/var/lib/openshift/51cd757de0b8cd31130000c1/python/virtenv/lib/python2.7/site-packages/Django-1.5.1-py2.7.egg/django/core/handlers/wsgi.py", line 236, in __call__
    self.load_middleware()
  File "/var/lib/openshift/51cd757de0b8cd31130000c1/python/virtenv/lib/python2.7/site-packages/Django-1.5.1-py2.7.egg/django/core/handlers/base.py", line 45, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:
  File "/var/lib/openshift/51cd757de0b8cd31130000c1/python/virtenv/lib/python2.7/site-packages/Django-1.5.1-py2.7.egg/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/var/lib/openshift/51cd757de0b8cd31130000c1/python/virtenv/lib/python2.7/site-packages/Django-1.5.1-py2.7.egg/django/conf/__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "/var/lib/openshift/51cd757de0b8cd31130000c1/python/virtenv/lib/python2.7/site-packages/Django-1.5.1-py2.7.egg/django/conf/__init__.py", line 134, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'www_project.settings' (Is it on sys.path?): No module named openshiftlibs
<WSGIServer fileno=6 address=127.5.232.1:8080>: Failed to handle request:
  request = GET /favicon.ico HTTP/1.1 from ('127.5.232.1', 22073)
  application = <django.core.handlers.wsgi.WSGIHandler object at 0x7f65c45dc510>

What I did?:

  1. Created an application using rhc command line tool
  2. Created an "isolated Django application" and copied into the wsgi directory
  3. Replaced the application and settings file for the official django example
  4. Pushed and tried

This is my application file:

#!/usr/bin/env python
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'www_project.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'www_project'))
virtenv = os.environ['OPENSHIFT_REPO_DIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.7/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except:
    pass

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

My question:

What am I missing?, if you need something else please let me know. Thanks in advance!

Upvotes: 2

Views: 939

Answers (3)

chachan
chachan

Reputation: 2462

I was missing the openshiftlibs.py file

Upvotes: 1

Hernan Ramirez
Hernan Ramirez

Reputation: 645

I had that problem and solved it with this post

http://appsembler.com/blog/django-deployment-using-openshift/

Upvotes: 0

Related Questions