$ sudo yum install rubygems git $ sudo gem install rhc $ rhc setup $ rhc app create habr python-2.6 
$ cd habr/wsgi/ $ django-admin startproject habr #!/usr/bin/env python # some original codes we need import os virtenv = os.environ['APPDIR'] + '/virtenv/' os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages') virtualenv = os.path.join(virtenv, 'bin/activate_this.py') try: execfile(virtualenv, dict(__file__=virtualenv)) except: pass # new codes we adding for Django import sys import django.core.handlers.wsgi os.environ['DJANGO_SETTINGS_MODULE'] = os.environ['OPENSHIFT_APP_NAME']+'.settings' sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', os.environ['OPENSHIFT_APP_NAME'])) application = django.core.handlers.wsgi.WSGIHandler() install_requires=['Django>=1.3'], $ git add habr $ git commit -a -m "Initialization" $ git push 
$ rhc cartridge add mysql-5.1 -a habr Added mysql-5.1 to application habr MySQL 5.1 database added. Please make note of these credentials: Root User: Root Password: Database Name: habr Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/ You can manage your new MySQL database by also embedding phpmyadmin-3.4. The phpmyadmin username and password will be the same as the MySQL credentials above. $ rhc cartridge add phpmyadmin-3.4 -a habr 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': os.environ['OPENSHIFT_APP_NAME'], # Or path to database file if using sqlite3. 'USER': os.environ['OPENSHIFT_MYSQL_DB_USERNAME'], # Not used with sqlite3. 'PASSWORD': os.environ['OPENSHIFT_MYSQL_DB_PASSWORD'], # Not used with sqlite3. 'HOST': os.environ['OPENSHIFT_MYSQL_DB_HOST'], # Set to empty string for localhost. Not used with sqlite3. 'PORT': os.environ['OPENSHIFT_MYSQL_DB_PORT'], # Set to empty string for default. Not used with sqlite3. $ git commit -a -m "db init" $ git push $ rhc tail habr $ django-admin startapp habrapp 'habrapp', <!DOCTYPE html> <html lang="ru"> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="/media/css/style.css" type="text/css" /> <title>{{title}}</title> </head> <body> <h3>{{text}}</h3> </body> </html> from django.shortcuts import render_to_response def index(request): c = { 'title': 'Habratitle', 'text': 'Hello habrahabr from OpenShift!',} return render_to_response('index.html',c) (r'^$','habrapp.views.index'), TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__),'templates').replace('\\','/'), ) $ git add templates/ $ git add habrapp/ $ git commit -a -m 'views add' $ git push $ python manage.py collectstatic RewriteEngine On
RewriteRule ^application/media/(.+)$ /static/media/$1 [L] h3 { color: #6DA3BD; } $ git add . $ git add . $ git add .htaccess $ git commit -a -m 'media files' $ git push Source: https://habr.com/ru/post/177243/
All Articles