2018年10月13日土曜日

開発環境

  • macOS Mojave - Apple
  • Emacs (Text Editor)
  • Python 3.7 (プログラミング言語)

Head First Python 第2版 ―頭とからだで覚えるPythonの基本 (Paul Barry (著)、嶋田 健志 (監修)、木下 哲也 (翻訳)、オライリージャパン)の10章(関数デコレーター - 関数を包む)、自分で考えてみよう(p. 375)を取り組んでみる。

コード(Emacs)

Python 3

# 1. session を追加
from flask import Flask, session

app = Flask(__name__)

# 2. secret_keyを追加
app.secret_key = '秘密の鍵'


@app.route('/login')
def do_login() -> str:
    session['logged_in'] = True
    return '現在ログインしています。'


if __name__ == '__main__':
    app.run(debug=True)

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

$ python3 simple_webapp.py
 * Serving Flask app "simple_webapp" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 178-619-558
127.0.0.1 - - [13/Oct/2018 13:39:48] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [13/Oct/2018 13:39:48] "GET /favicon.ico HTTP/1.1" 404 -
  C-c C-c$ 

0 コメント:

コメントを投稿