Skip to content

Instantly share code, notes, and snippets.

@suhailvs
Last active August 29, 2015 13:56
Show Gist options
  • Save suhailvs/8951091 to your computer and use it in GitHub Desktop.
Save suhailvs/8951091 to your computer and use it in GitHub Desktop.
Openshift python -2.7, django-1.6 example

Steps to create in OPENSHIFT

  1. Create a Python27 app in Openshift

create a python2.7 application in openshift

if you still don't uploaded the ssh publickey to openshift, then doit:

create an sshkey ssh-keygen -t rsa and upload the publickey(cat ~/.ssh/id_rsa.pub) to openshift

  1. Clone the application using git

ie git clone ssh://52fb16fa4382..@n-suhail.rhcloud.com/~/git/n.git/

Now a folder is created with files : requirements.txt,setup.py and wsgi.py

  1. Edit the file wsgi.py

Replace the whole content by:

Note: You need to search and replace <Project Name> with your django project name:

#!/usr/bin/python
import os, sys

os.environ['DJANGO_SETTINGS_MODULE'] = '<Project Name>.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'],'<Project Name>'))

virtenv = os.path.join(os.environ['OPENSHIFT_PYTHON_DIR'],'virtenv')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:execfile(virtualenv, dict(__file__=virtualenv))
except IOError:pass

from django.core.handlers import wsgi
application = wsgi.WSGIHandler()
  1. Edit the setup.py file :

You need to edit line:

install_requires=['Django',],
  1. Copy your django project folder to it

or you can also run: django-admin.py startproject <project Name>

  1. To serve static files

add to below lines to your project's urls.py:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

#only work if DEBUG is True 
urlpatterns += staticfiles_urlpatterns()
  1. create a .gitignore file

*.py[cow]
*~
*.sqlite3
yatchclub/modules

it is important to add sqlite database file or else each time you push, the database gets replaced.

you can also add unwanted folders like: yatchclub/modules

  1. Commit and push to server

git add .
git commit -a -m "Initialization"
git push
  1. ssh into app and run syncdb

ssh 53259e404382ec406d00002d@elance-picks.rhcloud.com
cd app-root/repo/<Project Name>/
python manage.py syncdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment