Skip to content

Instantly share code, notes, and snippets.

@Liyuu8
Last active November 19, 2018 16:44
Show Gist options
  • Save Liyuu8/0c0f01dc392a3ed11f7da5bffaa31866 to your computer and use it in GitHub Desktop.
Save Liyuu8/0c0f01dc392a3ed11f7da5bffaa31866 to your computer and use it in GitHub Desktop.
# 仮想環境venvを作成
$ python3.7 -m venv venv
$ source venv/bin/activate
# 最新バージョンのFlaskをインストール
(venv)$ pip install -U Flask
# norilog/templates/index.html
# norilog/static/main.css
# norilog/norilog.py
# HTML,CSS,Python のプログラムをそれぞれ作成
# データ形式はJSONを使用
# norilog.py がカレントディレクトリにある状態で
# Python を対話モードで起動
# save_data() 関数をロードして実行
(venv) vagrant@ubuntu-xenial:/vagrant_data/src/norilog$ python
>>> import datatime
>>> from norilog import save_data
>>> save_data('新宿', '渋谷', 'Halloween!', datetime.datetime(2017, 10, 31, 10, 0, 0))
>>> exit()
# save_data() 関数の出力を確認
(venv) vagrant@ubuntu-xenial:/vagrant_data/src/norilog$ cat norilog.json
[
{
"start": "新宿",
"finish": "渋谷",
"memo": "Halloween!",
"created_at": "2017-10-31 10:00"
}
]
# load_data() 関数の動作を確認
(venv) vagrant@ubuntu-xenial:/vagrant_data/src/norilog$ python
>>> from norilog import load_data
>>> load_data()
[{'start': '新宿', 'finish': '渋谷', 'memo': 'Halloween!', 'created_at': '2017-10-31 10:00'}]
# Webアプリケーションを実行
(venv) vagrant@ubuntu-xenial:/vagrant_data/src/norilog$ python norilog.py
* Serving Flask app "norilog" (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://0.0.0.0:8000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 151-987-433
192.168.33.1 - - [25/Oct/2018 16:37:21] "GET / HTTP/1.1" 200 -
192.168.33.1 - - [25/Oct/2018 16:37:21] "GET /static/main.css HTTP/1.1" 200 -
* Detected change in '/vagrant_data/src/norilog/norilog.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 151-987-433
* Detected change in '/vagrant_data/src/norilog/norilog.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 151-987-433
* Detected change in '/vagrant_data/src/norilog/norilog.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 151-987-433
* Detected change in '/vagrant_data/src/norilog/norilog.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 151-987-433
192.168.33.1 - - [25/Oct/2018 16:55:39] "GET / HTTP/1.1" 200 -
192.168.33.1 - - [25/Oct/2018 16:56:23] "POST /save HTTP/1.1" 302 -
192.168.33.1 - - [25/Oct/2018 16:56:23] "GET / HTTP/1.1" 200 -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment