最近のWebアプリケーションフレームワークだと、「開発している時はファイルの変更を検知して自動でアプリを再起動する」みたいな機能がある。PythonのFlaskで開発している場合は #!/usr/bin/env python from flask import Flask app = Flask(__name__) app.config.update({'DEBUG': True }) @app.route('/') def root(): return "Hello world!" if __name__ == '__main__': app.run() というコードを $ python main.py のように実行していると * Running on http://127.0.0.1:5000/ * Restarting with reloader となって自動リロードが有効になる。た
概要 まずは先に二つの記事をどうぞ DynamoDB HTTP API が独特な仕様なので紹介 Python の JSON Schema ライブラリを使ってみる さて、 最近は JSON を受け取って JSON を返す、この仕組みを実装する事が多いのですが、HTTP ベースとなると色々辛くなってきます。URL の設計、メソッドの選択などなど。もう面倒くさいから URL や メソッドは統一してしまいます。 機能判定は HTTP の独自定義したヘッダーを使う X-Amz-Target: DynamoDB_20120810.PutItem X-<会社名?>-Target: サービス名_日付.機能名 URL は / のみ メソッドは POST のみ 全てのやりとりは JSON で バリデーションは Req/Res 両方を JSON スキーマを使う とにかく頑張らない仕組みを作ります。 ライブラリの
from flask import Flask app = Flask(__name__) import json_schema import json schema = { "name": { "type": "string", "required": True }, "age": { "type": "number", "required": True "maximum": 120, "minimum": 0 } } @app.route("/") @json_schema.validate("POST", schema) def index(): if request.is_post: data = json.loads(request.data) print data["name"] print data["age"] return "Hi! "+data["name"] else
Flask-Via¶ Inspired by the Django URL configuration system, Flask-Via is designed to add similar functionality to Flask applications which have grown beyond a simple single file application. from flask import Flask from flask.ext.via import Via from flask.ext.via.routers.default import Functional app = Flask(__name__) def foo(bar=None): return 'Foo View!' routes = [ Functional('/foo', foo), Functi
Explore Flask¶ Explore Flask is a book about best practices and patterns for developing web applications with Flask. The book was funded by 426 backers on Kickstarter in July 2013. I finally released the book, after spending almost a year working on it. Almost immediately I was tired of managing distribution and limiting the book’s audience by putting it behind a paywall. I didn’t write a book to
Multiple Apps The application context (and its purpose) is indeed confusing until you realize that Flask can have multiple apps. Imagine the situation where you want to have a single WSGI Python interpreter run multiple Flask application. We're not talking Blueprints here, we're talking entirely different Flask applications. You might set this up similar to the Flask documentation section on "Appl
Flask アプリのテストで、簡単なものなら sqlite のメモリDBを使えば良いですが、複雑なアプリだと本番環境と同じ RDBMS を使って実行したいことが多いです。 その際、テストごとにDBを初期化すると遅いので、コミットせずに毎回ロールバックで対応したいのですが、 Flask.test_client や WebTest などを使って複数のHTTPリクエストを行うテストでは、リクエストをまたいでデータを引き継ぐ必要があります。 これを実現するために、 テスト中は session.commit() を session.flush(), session.expire_all() に置き換える リクエスト終了時、通常は session.remove() し、テスト中は session.expire_all() する テストごとに session.remove() する。 というカスタマイズ
Hi there, I'm Vadim 👋 I run a software business, build products and solve problems — occasionally a computer is involved. I'm co-founder & CTO at a digital agency in Zurich, Switzerland. The past 15 years I've been mostly solving technical challenges and leading software development in one role or the other. As a side thing, I enjoy sharing my experience and helping developers grow into CTOs / Te
概要 Todo list using RethinkDB, Flask, and Backbone.js - RethinkDB RethinkDB のサイトにあるサンプルアプリを移植してみた。 構成は Golang + Martini + Backbone.js + RethinkDB です。 といっても書いたのは Maritini と Golang から RethinkDB に繋ぐところだけですね。HTML はリンク部分だけ修正しました。あとは弄ってません。 コード自体はとても小さいので、さくっと移植出来るかなと思ったが、そもそも Golang 力が無かった ... ので結構苦労しました。 TODO 今回やらなかった事 GitHub にソースコードを公開する m.Group を使う static をバイナリに含めるようにする Martini メモ m.Use(martini.Stati
やりたいこと Redisをセッションデータの保存先にしたい Beakerって? 様々なデータストアにセッションデータを保存するWSGI Middleware。WSGIレイヤーなのでFlask以外のWAF(bottleとか)でも使えるはず。 必要なもの Python 2.6+ (自分はPython 3.3.4で動かしてる) Flask Beaker beaker_extensions - beakerだけだとRedisには対応してないためこれが必要 redis-py Redis サンプルコード gist9811874 動かす $ pip install beaker flask redis git+git://github.com/bbangert/beaker_extensions.git $ python beaker_sample.py http://localhost:5000/ に
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く