2018年5月24日木曜日

開発環境

入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の9章(ウェブを解きほぐす)、9.4(復習問題)4、5.を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3

print('9-4、5')

from flask import Flask, request, render_template
app = Flask(__name__)

import webbrowser
webbrowser.open('http://localhost:5000/?thing=THING&height=HEIGHT&color=COLOR')


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


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

入出力結果(Terminal, Jupyter(IPython))

$ ./sample2.py
9-4、5
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
9-4、5
 * Debugger is active!
 * Debugger PIN: 873-014-066
127.0.0.1 - - [24/May/2018 22:11:08] "GET /?thing=THING&height=HEIGHT&color=COLOR HTTP/1.1" 200 -
^C$

0 コメント:

コメントを投稿