[Django]-How to configure Django on OpenShift?

30👍

I finally figured it out. The first thing to do is to start an openshift app and edit the setup.py file :

rhc app create -a APPNAME -t python-2.6
cd APPNAME
vim setup.py

You need to uncomment “install_requires=[‘Django>=1.3’]”

Then you can commit to the server :

git commit -a -m "Initialization"
git push

By default, it installs django 1.4 but I think you can choose another version with the correct install requirement in setup.py. Anyway, you’ll have to run the same django version on your computer and the server for the following.

Create your django project :

cd wsgi
django-admin.py startproject PROJECTNAME

Then you’ll have to edit the file application, replace the whole content by :

#!/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/python2.6/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()

Finally, you can commit the modifications :

cd ..
git add .
git commit -a -m "Project Creation"
git push

You should see the django welcome page.
Now you can edit the settings and import your django apps without unwanted content

Leave a comment