OPenshift上的盒式Python2.7

OPenshift上的盒式Python2.7,python,django,openshift,Python,Django,Openshift,我尝试在主机Openshift上安装Django 1.5。我使用盒式Python 2.7。我读书。我不明白这个代码应该在哪里 virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/' virtualenv = os.path.join(virtenv, 'bin/activate_this.py') try: # See: http://stackoverflow.com/questions/23418735/using-pytho

我尝试在主机Openshift上安装Django 1.5。我使用盒式Python 2.7。我读书。我不明白这个代码应该在哪里

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 

此代码应位于文件
wsgi.py
中?请给我一个关于盒式python Openshift的示例工作应用程序。

是的,这段代码应该放在wsgi.py文件中

例如(尽管该示例使用的是3.3版,但它将为您指明正确的方向),请查看提供的答案下的注释: