2015年3月15日日曜日

開発環境

  • OS X Yosemite - Apple (OS)
  • Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
  • Python 3.4 (プログラミング言語)

Introducing Python: Modern Computing in Simple Packages(Bill Lubanovic (著)、 O'Reilly Media)のChapter 8(The Web, Untangled)、Things to Do 9.5.を解いてみる。

Things to Do 9.5.

コード(Eacs, BBEdit)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import flask

app = flask.Flask(__name__)

@app.route('/')
def home():
    thing = flask.request.args.get('thing')
    height = flask.request.args.get('height')
    color = flask.request.args.get('color')
    return flask.render_template('home.html', thing=thing, height=height,
                                 color=color)

app.run(port=5000, debug=True)

入出力結果(Terminal, IPython)

$ ./sample5.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
127.0.0.1 - - [15/Mar/2015 11:44:34] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [15/Mar/2015 11:44:52] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [15/Mar/2015 11:45:01] "GET /?thing=thing&color=red&height=20 HTTP/1.1" 200 -
127.0.0.1 - - [15/Mar/2015 11:45:25] "GET /?thing=Flask&height=100&color=Red HTTP/1.1" 200 -
  C-c C-c$

0 コメント:

コメントを投稿