- 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
- Clone the application using git
ie git clone ssh://[email protected]/~/git/n.git/
Now a folder is created with files : requirements.txt
,setup.py
and wsgi.py
- 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()
- Edit the
setup.py
file :
You need to edit line:
install_requires=['Django',],
- Copy your
django project
folder to it
or you can also run: django-admin.py startproject <project Name>
- 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()
- 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
- Commit and push to server
git add .
git commit -a -m "Initialization"
git push
- ssh into app and run
syncdb
ssh [email protected]
cd app-root/repo/<Project Name>/
python manage.py syncdb