LoginSignup
36

More than 5 years have passed since last update.

Python+Flask+Herokuで簡単webアプリ

Last updated at Posted at 2015-03-26

あいさつ

Rubyからの視点で色々備忘を綴ります.

pip, pip3

gemみたいなやつ、

python3に同梱されているヤツはpip3

virtualenv

Bundlerみたいなやつ

$ pip3 install virtualenv

bundle init みたいなコマンドでisolatedな環境を作る

$ virtualenv venv

bundle exec みたいなコマンドを打つ

$ source venv/bin/activate

Flask

Sinatraみたいなやつ

$ pip install flask

Gunicorn

webサーバー、unicornみたいなやつ

$ pip install gunicorn

アプリを作り始める

test_appという名前だとします.

$ mkdir test_app; cd test_app


$ touch main.py Procfile
main.py
import os
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello World!'
Procfile
web: gunicorn main:app --log-file=-

起動

$ foreman start

簡単や...

Gemfile.lock的なものを作る

$ pip freeze > requirements.txt

git

$ git init

$ echo 'venv\n*.pyc' > .gitignore

heroku

$ heroku create test-app

$ git push heroku master

$ heroku open

あとは

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36