Cartridge Python2.7 on OPenshift

91 views Asked by At

I try to install Django 1.5 on host Openshift. I use cartridge Python 2.7. I read https://developers.openshift.com/en/python-getting-started.html. I did not understand where this code should be.

virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
  # See: http://stackoverflow.com/questions/23418735/using-python-3-3-in-openshifts-book-example?noredirect=1#comment35908657_23418735
  #execfile(virtualenv, dict(__file__=virtualenv)) # for Python v2.7
  #exec(compile(open(virtualenv, 'rb').read(), virtualenv, 'exec'), dict(__file__=virtualenv)) # for Python v3.3
  # Multi-Line for Python v3.3:
  exec_namespace = dict(__file__=virtualenv)
  with open(virtualenv, 'rb') as exec_file:
  file_contents = exec_file.read()
  compiled_code = compile(file_contents, virtualenv, 'exec')
  exec(compiled_code, exec_namespace)
except IOError:
pass 

This code should be in file wsgi.py? Appeal, give me sample working application on cartridge python Openshift.

1

There are 1 answers

0
rshorey On BEST ANSWER

Yes, this code should go in the wsgi.py file.

For an example (although the example uses version 3.3, it'll point you in the right direction), look at the comments under the answer provided: Using Python 3.3 in OpenShift's book example