disruptive
disruptive

Reputation: 5946

Installing / Creating a Django app on Openshift

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!

Upvotes: 0

Views: 1005

Answers (2)

xtrinch
xtrinch

Reputation: 2281

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.

Upvotes: 0

argaen
argaen

Reputation: 4245

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.

Upvotes: 2

Related Questions