git 使用 openshift 部署本地 django 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26871381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:32:50  来源:igfitidea点击:

Deploying a local django app using openshift

pythondjangogitopenshift

提问by Oliver Burdekin

I've built a webapp using django. In order to host it I'm trying to use openshift but am having difficulty in getting anything working. There seems to be a lack of step by steps for this. So far I have git working fine, the app works on the local dev environment and I've successfully created an app on openshift.

我已经使用 django 构建了一个 webapp。为了托管它,我正在尝试使用 openshift,但无法正常工作。似乎缺乏这方面的步骤。到目前为止,我的 git 工作正常,该应用程序可在本地开发环境中运行,并且我已成功在 openshift 上创建了一个应用程序。

Following the URL on openshift once created I just get the standard page of "Welcome to your Openshift App".

按照创建后的 openshift 上的 URL,我只会看到“欢迎使用您的 Openshift 应用程序”的标准页面。

I've followed this https://developers.openshift.com/en/python-getting-started.html#step1to try changing the wsgi.py file. Changed it to hello world, pushed it and yet I still get the openshift default page.

我已经按照这个https://developers.openshift.com/en/python-getting-started.html#step1尝试更改 wsgi.py 文件。将其更改为 hello world,推送它,但我仍然获得 openshift 默认页面。

Is there a good comprehensive resource anywhere for getting local Django apps up and running on Openshift? Most of what I can find on google are just example apps which aren't that useful as I already have mine built.

是否有一个很好的综合资源可以让本地 Django 应用程序在 Openshift 上启动和运行?我在谷歌上可以找到的大部分内容只是示例应用程序,因为我已经构建了我的应用程序,所以它们并不是那么有用。

回答by Luis Masuelli

Edit: Remember this is a platform-dependent answer and since the OpenShift platform serving Django may change, this answer could become invalid. As of Apr 1 2016, this answer remains valid at its whole extent.

编辑请记住,这是一个依赖于平台的答案,并且由于为 Django 提供服务的 OpenShift 平台可能会发生变化,因此该答案可能无效。截至 2016 年 4 月 1 日,此答案在整个范围内仍然有效。

Many times this happened to me and, since I had to mount at least 5 applications, I had to create my own lifecycle:

很多时候这种情况发生在我身上,因为我必须至少挂载 5 个应用程序,所以我必须创建自己的生命周期:

  1. Don't use the Django cartridge, but the python 2.7 cartridge. Using the Django cart. and trying to update the django version brings many headaches, not included if you do it from scratch.
  2. Clone your repository via git. You will get yourprojectand...

    # git clone [email protected]:app.git yourproject <- replace it with your actual openshift repo address
    
    yourproject/
    +---wsgi.py
    +---setup.py
    *---.openshift/ (with its contents - I omit them now)
    
  3. Make a virtualenv for your brand-new repository cloned into your local machine. Activate it and install Django via pipand all the dependencies you would need (e.g. a new Pillow package, MySQL database package, ...). Create a django project there. Say, yourdjproject. EditCreate, alongside, a wsgi/staticdirectory with an empty, dummy, file (e.g. .gitkeep- the name is just convention: you can use any name you want).

     #assuming you have virtualenv-wrapper installed and set-up
     mkvirtualenv myenvironment
     workon myenvironment
     pip install Django[==x.y[.z]] #select your version; optional.
     #creating the project inside the git repository
     cd path/to/yourproject/
     django-admin.py startproject yourjdproject .
     #creating dummy wsgi/static directory for collectstatic
     mkdir -p wsgi/static
     touch wsgi/static/.gitkeep
    
  4. Create a django app there. Say, yourapp. Include it in your project.

  5. You will have something like this (django 1.7):

    yourproject/
    +---wsgi/
    |   +---static/
    |       +---.gitkeep
    +---wsgi.py
    +---setup.py
    +---.openshift/ (with its contents - I omit them now)
    +---yourdjproject/
    |   +----__init__.py
    |   +----urls.py
    |   +----settings.py
    |   +----wsgi.py
    +---+yourapp/
        +----__init__.py
        +----models.py
        +----views.py
        +----tests.py
        +----migrations
             +---__init__.py
    
  6. Set up your django application as you'd always do (I will not detail it here). Remember to include all the dependencies you installed, in the setup.py file accordingly (This answer is not the place to describe WHY, but the setup.py is the package installer and openshift uses it to reinstall your app on each deploy, so keep it up to date with the dependencies).

  7. Create your migrations for your models.
  8. Edit the openshift-given WSGI script as follows. You will be including the django WSGI application AFTER including the virtualenv (openshift creates one for python cartridges), so the pythonpath will be properly set up.

    #!/usr/bin/python
    import os
    virtenv = 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 yourdjproject.wsgi import application
    
  9. Edit the hooks in .openshift/action_hooks to automatically perform db sincronization and media management:

    build hook

    #!/bin/bash
    #this is .openshift/action/hooks/build
    #remember to make it +x so openshift can run it.
    if [ ! -d ${OPENSHIFT_DATA_DIR}media ]; then
        mkdir -p ${OPENSHIFT_DATA_DIR}media
    fi
    ln -snf ${OPENSHIFT_DATA_DIR}media $OPENSHIFT_REPO_DIR/wsgi/static/media
    
    ######################### end of file
    

    deploy hook

    #!/bin/bash
    #this one is the deploy hook .openshift/action_hooks/deploy
    source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate
    cd $OPENSHIFT_REPO_DIR
    echo "Executing 'python manage.py migrate'"
    python manage.py migrate
    echo "Executing 'python manage.py collectstatic --noinput'"
    python manage.py collectstatic --noinput
    
    ########################### end of file
    
  10. Now you have the wsgi ready, pointing to the django wsgi by import, and you have your scripts running. It is time to consider the locations for static and media files we used in such scripts. Edit your Django settings to tell where did you want such files:

    STATIC_URL = '/static/'
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static')
    MEDIA_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static', 'media')
    STATICFILES_DIRS = (os.path.join(BASE_DIR, 'yourjdproject', 'static'),)
    TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'yourjdproject', 'templates'),)
    
  11. Create a sample view, a sample model, a sample migration, and PUSH everything.

  12. EditRemember to put the right settings to consider both environments so you can test and run in a local environment AND in openshift (usually, this would involve having a local_settings.py, optionally imported if the file exists, but I will omit that part and put everything in the same file). Please read this file conciously since things likeyourlocaldbnameare values you MUST set accordingly:

    """
    Django settings for yourdjproject project.
    
    For more information on this file, see
    https://docs.djangoproject.com/en/1.7/topics/settings/
    
    For the full list of settings and their values, see
    https://docs.djangoproject.com/en/1.7/ref/settings/
    """
    
    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    import os
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    
    ON_OPENSHIFT = False
    if 'OPENSHIFT_REPO_DIR' in os.environ:
        ON_OPENSHIFT = True
    
    
    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
    
    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = '60e32dn-za#y=x!551tditnset(o9b@2bkh1)b$hn&0$ec5-j7'
    
    # Application definition
    
    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'yourapp',
        #more apps here
    )
    
    MIDDLEWARE_CLASSES = (
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
    )
    
    ROOT_URLCONF = 'yourdjproject.urls'
    
    WSGI_APPLICATION = 'yourdjproject.wsgi.application'
    
    # Database
    # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
    
    if ON_OPENSHIFT:
        DEBUG = True
        TEMPLATE_DEBUG = False
        ALLOWED_HOSTS = ['*']
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': 'youropenshiftgenerateddatabasename',
                'USER': os.getenv('OPENSHIFT_MYSQL_DB_USERNAME'),
                'PASSWORD': os.getenv('OPENSHIFT_MYSQL_DB_PASSWORD'),
                'HOST': os.getenv('OPENSHIFT_MYSQL_DB_HOST'),
                'PORT': os.getenv('OPENSHIFT_MYSQL_DB_PORT'),
                }
        }
    else:
        DEBUG = True
        TEMPLATE_DEBUG = True
        ALLOWED_HOSTS = []
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.mysql', #If you want to use MySQL
                'NAME': 'yourlocaldbname',
                'USER': 'yourlocalusername',
                'PASSWORD': 'yourlocaluserpassword',
                'HOST': 'yourlocaldbhost',
                'PORT': '3306', #this will be the case for MySQL
            }
        }
    
    # Internationalization
    # https://docs.djangoproject.com/en/1.7/topics/i18n/
    
    LANGUAGE_CODE = 'yr-LC'
    TIME_ZONE = 'Your/Timezone/Here'
    USE_I18N = True
    USE_L10N = True
    USE_TZ = True
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.7/howto/static-files/
    
    STATIC_URL = '/static/'
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static')
    MEDIA_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static', 'media')
    STATICFILES_DIRS = (os.path.join(BASE_DIR, 'yourdjproject', 'static'),)
    TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'yourdjproject', 'templates'),)
    
  13. Git add, commit, push, enjoy.

    cd path/to/yourproject/
    git add .
    git commit -m "Your Message"
    git push origin master # THIS COMMAND WILL TAKE LONG
    # git enjoy
    
  14. Your sample Django app is almost ready to go! But if your application has external dependencies it will blow with no apparent reason. This is the reason I told you to develop a simple application. Now it is time to make your dependencies work.

    [untested!] You can edit the deploy hook and add a command after the command cd $OPENSHIFT_REPO_DIR, like this: pip install -r requirements.txt, assuming the requirements.txt file exists in your project. pipshould exist in your virtualenv, but if it does not, you can see the next solution.

    Alternatively, the setup.py is an already-provided approach on OpenShift. What I did many times is -assuming the requirements.txt file exists- is:

    1. Open that file, read all its lines.
    2. For each line, if it has a #, remove the # and everything after.
    3. stripleading and trailing whitespaces.
    4. Discard empty lines, and have the result (i.e. remaining lines) as an array.
    5. That result must be assigned to the install_requires=keyword argument in the setupcall in the setup.py file.

    I'm sorry I did not include this in the tutorial before!But you need to actually install Django in the server. Perhaps an obvious suggestion, and every Python developer could know that beforehand. But seizing this opportunity I remark: Include the appropriate Django dependency in the requirements.txt (or setup.py depending on whetheryou use or not a requirements.txt file), as you include any other dependency.

  1. 不要使用 Django 墨盒,而是使用 python 2.7 墨盒。使用 Django 购物车。尝试更新 django 版本会带来很多麻烦,如果您从头开始,则不包括在内。
  2. 通过 git 克隆您的存储库。你会得到yourproject和...

    # git clone [email protected]:app.git yourproject <- replace it with your actual openshift repo address
    
    yourproject/
    +---wsgi.py
    +---setup.py
    *---.openshift/ (with its contents - I omit them now)
    
  3. 为克隆到本地计算机的全新存储库创建一个 virtualenv。激活它并通过pip您需要的所有依赖项(例如新的 Pillow 包、MySQL 数据库包等)安装 Django 。在那里创建一个 django 项目。说,你的djproject。编辑创建一个wsgi/static带有空的虚拟文件的目录(例如.gitkeep- 名称只是约定:您可以使用任何您想要的名称)。

     #assuming you have virtualenv-wrapper installed and set-up
     mkvirtualenv myenvironment
     workon myenvironment
     pip install Django[==x.y[.z]] #select your version; optional.
     #creating the project inside the git repository
     cd path/to/yourproject/
     django-admin.py startproject yourjdproject .
     #creating dummy wsgi/static directory for collectstatic
     mkdir -p wsgi/static
     touch wsgi/static/.gitkeep
    
  4. 在那里创建一个 django 应用程序。说,你的应用程序。将其包含在您的项目中。

  5. 你会有这样的东西(django 1.7):

    yourproject/
    +---wsgi/
    |   +---static/
    |       +---.gitkeep
    +---wsgi.py
    +---setup.py
    +---.openshift/ (with its contents - I omit them now)
    +---yourdjproject/
    |   +----__init__.py
    |   +----urls.py
    |   +----settings.py
    |   +----wsgi.py
    +---+yourapp/
        +----__init__.py
        +----models.py
        +----views.py
        +----tests.py
        +----migrations
             +---__init__.py
    
  6. 像往常一样设置您的 django 应用程序(我不会在这里详细说明)。请记住在 setup.py 文件中相应地包含您安装的所有依赖项(此答案不是描述原因的地方,但 setup.py 是包安装程序,openshift 使用它在每次部署时重新安装您的应用程序,因此请保留它与依赖项保持同步)。

  7. 为您的模型创建迁移。
  8. 如下编辑 openshift 给定的 WSGI 脚本。在包含 virtualenv(openshift 为 python 墨盒创建一个)之后,您将包含 django WSGI 应用程序,因此将正确设置 pythonpath。

    #!/usr/bin/python
    import os
    virtenv = 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 yourdjproject.wsgi import application
    
  9. 编辑 .openshift/action_hooks 中的 hooks 以自动执行 db sincronization 和媒体管理:

    构建钩子

    #!/bin/bash
    #this is .openshift/action/hooks/build
    #remember to make it +x so openshift can run it.
    if [ ! -d ${OPENSHIFT_DATA_DIR}media ]; then
        mkdir -p ${OPENSHIFT_DATA_DIR}media
    fi
    ln -snf ${OPENSHIFT_DATA_DIR}media $OPENSHIFT_REPO_DIR/wsgi/static/media
    
    ######################### end of file
    

    部署钩子

    #!/bin/bash
    #this one is the deploy hook .openshift/action_hooks/deploy
    source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate
    cd $OPENSHIFT_REPO_DIR
    echo "Executing 'python manage.py migrate'"
    python manage.py migrate
    echo "Executing 'python manage.py collectstatic --noinput'"
    python manage.py collectstatic --noinput
    
    ########################### end of file
    
  10. 现在您已经准备好 wsgi,通​​过导入指向 django wsgi,并且您的脚本正在运行。是时候考虑我们在此类脚本中使用的静态和媒体文件的位置了。编辑您的 Django 设置以了解您想要这些文件的位置:

    STATIC_URL = '/static/'
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static')
    MEDIA_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static', 'media')
    STATICFILES_DIRS = (os.path.join(BASE_DIR, 'yourjdproject', 'static'),)
    TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'yourjdproject', 'templates'),)
    
  11. 创建示例视图、示例模型、示例迁移和 PUSH 一切。

  12. 编辑请记住将正确的设置考虑到两种环境,以便您可以在本地环境和 openshift 中测试和运行(通常,local_settings.py如果文件存在,这将涉及有一个,可选择导入,但我将省略该部分并将所有内容放入同一个文件)。请有意识地阅读此文件,因为诸如yourlocaldbname 之类的值是您必须相应设置的值

    """
    Django settings for yourdjproject project.
    
    For more information on this file, see
    https://docs.djangoproject.com/en/1.7/topics/settings/
    
    For the full list of settings and their values, see
    https://docs.djangoproject.com/en/1.7/ref/settings/
    """
    
    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    import os
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    
    ON_OPENSHIFT = False
    if 'OPENSHIFT_REPO_DIR' in os.environ:
        ON_OPENSHIFT = True
    
    
    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
    
    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = '60e32dn-za#y=x!551tditnset(o9b@2bkh1)b$hn&0$ec5-j7'
    
    # Application definition
    
    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'yourapp',
        #more apps here
    )
    
    MIDDLEWARE_CLASSES = (
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
    )
    
    ROOT_URLCONF = 'yourdjproject.urls'
    
    WSGI_APPLICATION = 'yourdjproject.wsgi.application'
    
    # Database
    # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
    
    if ON_OPENSHIFT:
        DEBUG = True
        TEMPLATE_DEBUG = False
        ALLOWED_HOSTS = ['*']
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': 'youropenshiftgenerateddatabasename',
                'USER': os.getenv('OPENSHIFT_MYSQL_DB_USERNAME'),
                'PASSWORD': os.getenv('OPENSHIFT_MYSQL_DB_PASSWORD'),
                'HOST': os.getenv('OPENSHIFT_MYSQL_DB_HOST'),
                'PORT': os.getenv('OPENSHIFT_MYSQL_DB_PORT'),
                }
        }
    else:
        DEBUG = True
        TEMPLATE_DEBUG = True
        ALLOWED_HOSTS = []
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.mysql', #If you want to use MySQL
                'NAME': 'yourlocaldbname',
                'USER': 'yourlocalusername',
                'PASSWORD': 'yourlocaluserpassword',
                'HOST': 'yourlocaldbhost',
                'PORT': '3306', #this will be the case for MySQL
            }
        }
    
    # Internationalization
    # https://docs.djangoproject.com/en/1.7/topics/i18n/
    
    LANGUAGE_CODE = 'yr-LC'
    TIME_ZONE = 'Your/Timezone/Here'
    USE_I18N = True
    USE_L10N = True
    USE_TZ = True
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.7/howto/static-files/
    
    STATIC_URL = '/static/'
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static')
    MEDIA_ROOT = os.path.join(BASE_DIR, 'wsgi', 'static', 'media')
    STATICFILES_DIRS = (os.path.join(BASE_DIR, 'yourdjproject', 'static'),)
    TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'yourdjproject', 'templates'),)
    
  13. Git 添加、提交、推送、享受。

    cd path/to/yourproject/
    git add .
    git commit -m "Your Message"
    git push origin master # THIS COMMAND WILL TAKE LONG
    # git enjoy
    
  14. 您的示例 Django 应用程序几乎可以使用了!但是,如果您的应用程序具有外部依赖项,它就会毫无缘由地崩溃。这就是我告诉你开发一个简单应用程序的原因。现在是时候让您的依赖项工作了

    [未经测试!] 您可以编辑部署挂钩并在命令后添加一个命令cd $OPENSHIFT_REPO_DIR,如下所示:pip install -r requirements.txt假设您的项目中存在requirements.txt 文件。pip应该存在于您的 virtualenv 中,但如果不存在,您可以查看下一个解决方案。

    或者,setup.py 是 OpenShift 上已经提供的方法。我做的很多次是 - 假设 requirements.txt 文件存在 - 是:

    1. 打开那个文件,阅读它的所有行。
    2. 对于每一行,如果它有 #,则删除 # 和后面的所有内容。
    3. strip前导和尾随空格。
    4. 丢弃空行,并将结果(即剩余行)作为数组。
    5. 该结果必须分配给setup.py 文件中调用中的install_requires=关键字参数setup

    对不起,我之前没有在教程中包含这个!但是您需要在服务器中实际安装 Django。也许是一个明显的建议,每个 Python 开发人员都可以事先知道。但是抓住这个机会我说:在requirements.txt(或setup.py 取决于您是否使用requirements.txt 文件)中包含适当的Django 依赖项,因为您包含任何其他依赖项。

This should help you to mount a Django application, and took me a lot of time to standarize the process. Enjoy it and don't hesitate on contacting me via comment if something goes wrong

这应该可以帮助您挂载 Django 应用程序,并且花了我很多时间来标准化这个过程。享受它,如果出现问题,请不要犹豫,通过评论与我联系

Edit(for those with the same problem who don't expect to find the answer in this post's comments): Remember that if you edit the build or deploy hook files under Windows and you push the files, they will fly to the server with 0644 permissions, since Windows does not support this permission scheme Unix has, and has no way to assign permissions since these files do not have any extension. You will notice this because your scripts will not be executed when deploying. So try to deploy those files onlyfrom Unix-based systems.

编辑(对于那些有同样问题的人,不希望在这篇文章的评论中找到答案):记住,如果你在 Windows 下编辑构建或部署钩子文件并推送文件,它们会以 0644 飞到服务器权限,因为 Windows 不支持 Unix 具有的这种权限方案,并且无法分配权限,因为这些文件没有任何扩展名。您会注意到这一点,因为在部署. 因此,请尝试仅从基于 Unix 的系统部署这些文件。

Edit 2: You can use git hooks (e.g. pre_commit) to set permissions for certain files, like pipeline scripts (build, deploy, ...). See the comments by @StijndeWitt and @OliverBurdekin in this answer, and also this questionfor more details.

编辑 2:您可以使用 git 钩子(例如 pre_commit)为某些文件设置权限,例如管道脚本(构建、部署……)。请参阅@StijndeWitt 和@OliverBurdekin 在此答案中的评论,以及此问题的更多详细信息。

回答by Tanveer Alam

1)  Step 1 install  Rubygems
Ubuntu - https://rubygems.org/pages/download
Windows - https://forwardhq.com/support/installing-ruby-windows
$ gem
or
C:\Windows\System32>gem
RubyGems is a sophisticated package manager for Ruby.  This is a
basic help message containing pointers to more information……..

2)  Step 2:
$ gem install rhc
Or
C:\Windows\System32> gem install rhc

3)  $ rhc
Or
C:\Windows\System32> rhc

Usage: rhc [--help] [--version] [--debug] <command> [<args>]
Command line interface for OpenShift.

4)  $ rhc app create -a mysite -t python-2.7
Or 
C:\Windows\System32>  rhc app create -a mysite -t python-2.7
# Here mysite would be the sitename of your choice
#It will ask you to enter your openshift account id and password

Login to openshift.redhat.com: Enter your openshift id here
Password : **********


Application Options
---------------------
Domain:    mytutorials
Cartridges: python-2.7
Gear Size:  Default
Scaling:    no

......
......

Your application 'mysite' is now available.

 URL : http://mysite.....................
 SSH to :  39394949......................
 Git remote: ssh://......................

Run 'rhc show-app mysite' for more details about your app.

5)  Clone your site
$ rhc git-clone mysite
Or
D:\> rhc git-clone mysite
.......................
Your application Git repository has been cloned to "D:\mysite"

6)  #”D:\mysite>” is the location we cloned.
D:\mysite> git remote add upstream -m master git://github.com/rancavil/django-openshift-quickstart.git

D:\mysite> git pull -s recursive -X theirs upstream master

7)  D:\mysite> git push
remote : ................
remote: Django application credentials
               user: admin
               xertefkefkt

remote: Git Post-Receive Result: success
.............

8)  D:\mysite>virtualenv venv --no-site-packages
D:\mysite>venv\Scripts\activate.bat
<venv> D:\mysite> python setup.py install
creating .....
Searching for Django<=1.6
.............
Finished processing dependencies for mysite==1.0

9)  Change admin password
<venv> D:\mysite\wsgi\openshift> python manage.py changepassword admin
password:
...
Password changed successfully for user 'admin'
<venv> D:\mysite\wsgi\openshift> python manage.py runserver
Validating models….

10) Git add
<venv> D:\mysite> git add.
<venv> D:\mysite> git commit -am"activating the app on Django / Openshift"
   .......
<venv> D:\mysite> git push



#----------------------------------------------------------------------------------
#-----------Edit your setup.py in mysite with packages you want to install----------

from setuptools import setup

import os

# Put here required packages
packages = ['Django<=1.6',  'lxml', 'beautifulsoup4', 'openpyxl']

if 'REDISCLOUD_URL' in os.environ and 'REDISCLOUD_PORT' in os.environ and 'REDISCLOUD_PASSWORD' in os.environ:
     packages.append('django-redis-cache')
     packages.append('hiredis')

setup(name='mysite',
      version='1.0',
      description='OpenShift App',
      author='Tanveer Alam',
      author_email='[email protected]',
      url='https://pypi.python.org/pypi',
      install_requires=packages,
)

回答by Serjik

These are steps that works for me: I've done some steps manually, but you can automate them later to be done with each push command.

这些是对我有用的步骤:我已经手动完成了一些步骤,但是您可以在以后使用每个推送命令自动完成它们。

  1. Create new django app with python-3.3 from website wizard
  2. Add mysql cartridge to app (my option is mysql)
  3. git clone created app to local
  4. add requirements.txt to root folder
  5. Add myapp to wsgi folder
  6. Modify application to refer to myapp
  7. execute git add, commit, push
  8. Browse app and debug errors with "rhc tail myapp"
  9. connect to ssh console

    rhc ssh myapp

  1. 从网站向导使用 python-3.3 创建新的 django 应用程序
  2. 将mysql墨盒添加到应用程序(我的选项是mysql)
  3. git clone 创建的应用程序到本地
  4. 将 requirements.txt 添加到根文件夹
  5. 将 myapp 添加到 wsgi 文件夹
  6. 修改应用程序以引用 myapp
  7. 执行 git add、提交、推送
  8. 使用“rhc tail myapp”浏览应用程序并调试错误
  9. 连接到 ssh 控制台

    rhc ssh myapp

10.execute this

10.执行这个

source $OPENSHIFT_HOMEDIR/python/virtenv/venv/bin/activate
  1. install missing packages if any
  2. go to app directory

    cd ~/app-root/runtime/repo/wsgi/app_name

  3. do migration with:

    python manage.py migrate

  4. create super user:

    python manage.py createsuperuser

  1. 安装缺少的软件包(如果有)
  2. 转到应用程序目录

    cd ~/app-root/runtime/repo/wsgi/app_name

  3. 使用以下方法进行迁移:

    python manage.py 迁移

  4. 创建超级用户:

    python manage.py createsuperuser

15.Restart the app

15.重启应用