Monday, June 18, 2012

howto create a django application in openshift(wsgi related)

we are using openshift as our mobile app's backend since we don't have much resource and money to buy a server for hosting this backend site. It's a great Pass platform for developers saving much headaches. Every account has one domain associated, we can create 3 apps under it, e.g. you create a domain map, and then create a app social, the application's full URL will be social-map.rhcloud.com. You can check its features in http://openshift.redhat.com .

Django is our backend web framework, and there's a quick start example in github(github.com/openshift/django-example), you can just clone this repo, and push it to your repo, then openshift will deploy it for you.

But we decided to do it ourselves(why we need those unrelated dirs, codes, it's really annoying), it's very easy. Here are some steps:
1, clone your app repo into local working directory, when you create an app, openshift will create a git repo for you, and you can add other remote repos, and push/pull from there, it's up to you.
2, edit setup.py, add 'Django>=1.3' into install_requires
3, use django-admin.py creating a new project under your working directory, there will be one wsgi file generated, after step 4, you can delete this
4, edit wsgi/application file, you can setup environment vars there, the important thing is help it finding your site's setting.py
 5, ok, you have done the setup stuff, now you can continue your coding, and then push it to openshift


ps, our directory structure:
  .
|-- data
|-- libs
|-- socialmap   (this is our django project)
|   |-- accounts
|   |   `-- avatars
|   `-- templates
`-- wsgi      (wsgi file application mentioned in step4 is in this directory)
    `-- static
        `-- admin
            |-- css
            |-- img
            |   `-- gis
            `-- js
                `-- admin

1 comment:

  1. Hi Nathan!

    This tutorial is straightly simple and nice. However, I am looking to launch my project using Py 2.7 and Django 1.4

    So, I thought to use DIY using this tutorial:
    https://openshift.redhat.com/community/forums/openshift/how-to-setup-virtualenv-for-my-django-python-27-do-it-yourself-application

    But I am having some problems with uWsgi

    Its showing me

    *** WARNING: you are running uWSGI without its master process manager ***
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    bind(): Permission denied [socket.c line 745]

    So, can you help me in fixing it?

    ReplyDelete