0

I'm in the process of migrating an application to openshift - however I cannot seem to find much (any) documentation on actually getting an application to run in the PaaS. One major problem is knowing I should handle the wsgi.py file that is default when you create an application - in this case Python3.3.

Here is what I did:

  1. Create a python3.3 application from the rhc command.
  2. Clone the repository.
  3. edit the setup.py and un-comment out the requirement for Django (see link below).
  4. Try the wsgi.py suggestion of the below link (changing for the version of python)

How to configure Django on OpenShift?

Now I can see after the push that the django gets pulled in as a requirement (changes in setup.py). But I cannot work out what should be in the wsgi.py file - even a basic application that works as a template would be really useful but I simply cannot find one. Using the following for wsgi.py gives the following error:

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

os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECTNAME.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',
    'PROJECTNAME'))

virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python3.3/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')

try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

#
# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
#
from django.core.handlers import wsgi
application = wsgi.WSGIHandler()

Here is the error message:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/2.2.15 (Red Hat) Server at name-name.rhcloud.com Port 80

Here are the log files I get:

[Thu Jul 03 13:15:59 2014] [error] [client 127.8.250.1]     % (self.SETTINGS_MODULE, e)
[Thu Jul 03 13:15:59 2014] [error] [client 127.8.250.1] ImportError: Could not import settings 'name.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'name'
80.241.77.253 - - [03/Jul/2014:13:15:59 -0400] "GET /favicon.ico HTTP/1.1" 500 622 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"

A basic settings.py file would be useful too!

Community
  • 1
  • 1
disruptive
  • 5,687
  • 15
  • 71
  • 135

2 Answers2

2

os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECTNAME.settings' -> You must change the PROJECTNAME to your project folder name and same for the next one.

Btw, check out this and see if it helps: http://django.zone/posts/3 in case you are having more errors.

If you need a basic template application, you can check this github repo https://github.com/argaen/djangozone which is a blog simple enough to understand everything. You can also check this repo: https://github.com/openshift/django-example.

argaen
  • 4,145
  • 24
  • 28
  • Thanks. I tried your wsgi.py with the amendments but sadly I still get the same error. There is a question of what the folder name actually is called. The projectname is defined, but the URL has name-name. I tried all combinations name-name, and also name, name-name pairs and found that I cannot get any deviation from the original error message. – disruptive Jul 03 '14 at 14:50
  • Is the development server working correctly? If so, can you post your settings.py file? may be you missed to set ALLOWED_HOSTS variable or some other thing. This error isn't related with urls, it is a missconfiguration somewhere (wsgi, settings, syntax error..). Have you also tried to check your logs? rhc tail or ssh into it and read the log files? – argaen Jul 03 '14 at 15:01
  • I tried this and have pushed my log file summary up above. – disruptive Jul 03 '14 at 17:25
  • Lol, instead of name, you have to write the name of your project folder!! A basic settings file: https://github.com/argaen/djangozone/blob/master/wsgi/djangozone/settings.py Anyway, you have to replace name with your project folder as Ive said to fix this problem. The error is saying that to you: "ImportError: Could not import settings 'name.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'name'" – argaen Jul 03 '14 at 18:11
  • I changed my actual project name to name to avoid issues. Of course I changed .name to .myname where myname = name of project. Your suggestion whilst helpful still requires a standard settings file. – disruptive Jul 03 '14 at 20:18
0

The following in my wsgi.py:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings.prod")

application = get_wsgi_application()

and a requirements.txt file in my project root was enough to get my django app working.

xtrinch
  • 2,232
  • 1
  • 24
  • 46