Flask by Example – Project Setup – Real Python

Flask by Example – Project Setup – Real Python

Advertisements

Deploy Django Application to Heroku

Version

  • Python: 2.7.3
  • Django: 1.7

What to do on localhost?

Start from

Important thing is to run

python manage.py collectstatic

If you use public CDN at frontend and also use Django admin feauture,be sure to run it to show the admin style correctly after finishing your application.

Run Heroku commands

heroku run python manage.py sqlmigrate [your_app] 0001

The 0001 is the number of your migration.

heroku run python manage.py migrate

Until now,model tables have been created in your database.

Create superuser

heroku run python manage.py createsuperuser

That’s all.

Settings

https://github.com/zhangjingqiang/qiang-commands/blob/master/qiang_commands/settings.py

PaaSがもたらす未来と、Ruby活用の秘訣

Date: 2013/07/17(水) 午後 http://www.iij.ad.jp/news/seminar/2013/sm130717.html

日本国内クラウド市場概況

  • SaaS(Apps + SIS-aaS) 少ない
  • PaaS 中央
  • IaaS(Server + Basic Storage) 多い

Ruby(発表者:Matz)

  • 世界中100万Rubyユーザー?
  • 順位:11
  • RailsはDSLフレームワーク
  • Rails3 = Rails + Merb
  • Ruby 2.1 は2013年年末リリース

クラウドサービス運用コスト

IaaS

  • 最低料金は高め
  • スケールアウトにコストがかかる

PaaS

  • 最低料金は低め
  • IaaSより開発保守コストが高い
  • スケールアウトが容易

制限

  • PaaSはsshができない
  • ブロックストレージできない
  • IaaSの自由度が高い

日本のPaaS – MOGOK

  • 公式サイト:http://mogok.jp/

もう一つCMS – JoruriCMS

  • 公式サイト:http://joruri.org/
  • ソース:https://github.com/joruri/joruricms

Engine Yard

Facebook Stories

Heroku

  • 日本運営会社:http://www.salesforce.com/homepage-prosp/
  • 日本人社員:5人(4男1女)Matzを含む
  • サポートプログラミング言語:様々(Perlも予定)
  • Heroku Apps: 3,500,000
  • 40% apps are by Ruby

How to deploy Django app to Heroku?

1. Install some packages

pip install psycopg2 dj-database-url gunicorn

2. Create requirements.txt

pip freeze > requirements.txt

3. Config settings([APP_NAME]/settings.py)

import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'ribbit',                      # Or path to database file if using sqlite3.
        'USER': 'username',                      # Not used with sqlite3.
        'PASSWORD': 'password',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')
STATIC_URL = '/static/'

TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates')
)

import dj_database_url
DATABASES['default'] = dj_database_url.config()

4. Create Procfile

web: gunicorn [APP_NAME].wsgi

5. Add URLs([APP_NAME]/urls.py)

urlpatterns += patterns('django.contrib.staticfiles.views',
    url(r'^static/(?P.*)$', 'serve'),
)

6. Git commit

git commit -a -m 'Configured for Heroku'

7. Push to Heroku

git push heroku master

8. Apply the migrations to the Heroku database

heroku run python manage.py syncdb
heroku run python manage.py migrate ribbit_app

9. Enjoy it

heroku open

Links

Building Ribbit in Django