How to configure Django on OpenShift?

I recently tried to export a Django project on OpenShift, but fruitlessly. The only solutions I found were "prebuilt" ones (such as

I spent some hours trying to adapt it to my project but I always got an Internal Server Error.

So, how to setup django on openshift?


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

rhc app create -a APPNAME -t python-2.6

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 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 startproject PROJECTNAME

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

import os, sys

sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',

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/')

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

# 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

Need Your Help

How to route to a Module as a child of a Module - Angular 2 RC 5

angular angular2-routing angular2-modules angular2-router3

I am in the process upgrading an application I'm working on to the latest Angular 2 release candidate. As part of this work I am attempting to use the NgModule spec and migrating all of the parts o...