There were few changes in application structure on Openshift after its last release (https://blog.openshift.com/openshift-online-march-2014-release-blog/). Because of this I had some troubles with creating new Django application. Here I will describe steps for creating Django 1.7 application using Python 2.7 cartridge on Openshift.
There are two options for creating application on Openshift:
Both of these are described here https://developers.openshift.com/en/getting-started-overview.html#step3
Create empty Git repository on your machine:
mkdir repo_dir && cd repo_dir
Open your application and copy its SSH path (via GUI or by command
rhc domain show). It should be like
Clone it to your git repo:
git clone ssh://email@example.com/~/git/your-app.git/
You should see the following files structure:
repo_dir |-- requirements.txt |-- setup.py |-- wsgi.py
a) Install Django
pip install Django==1.7
b) Create your Django project
I use project template for this purpose
django-admin.py startproject --template=https://github.com/AnaPana/django-project-template/archive/master.zip --extension=py,js,css,html,txt my_project
Or empty default project can be created:
django-admin.py startproject my_project
c) Rearange project directories
If project was created from template, its root directory should be moved on one level up.
d) Final project structure
Finally there should the following project's structure:
repo_dir |-- my_project |-- manage.py └-- my_project |-- settings.py (or settings/production.py. settings/local.py etc) |-- urls.py └-- wsgi.py |-- requirements.txt |-- requirements/production.txt etc. (optional) |-- setup.py └-- wsgi.py
The next step is to put this content into
In my case it has the following code:
# wsgi.py import os from os.path import abspath, dirname from sys import path SITE_ROOT = dirname(dirname(abspath(__file__))) path.append(SITE_ROOT) path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'my_project')) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings.production") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
There should be proper path to your DJANGO_SETTINGS_MODULE.
Put your requirements in
requirements.txt file, e.g.:
# requirements.txt Django==1.7
git add *
git commit -m "First commit"
git push origin master
Enjoy your web application) Don't forget to add your web-app site address to ALLOWED_HOSTS in production settings. If you have questions just leave a comment. I'll be happy to help you.