https://github.com/ot-nemoto/flask-tutorial
Flask チュートリアル
https://github.com/ot-nemoto/flask-tutorial
flask tutorial
Last synced: about 1 year ago
JSON representation
Flask チュートリアル
- Host: GitHub
- URL: https://github.com/ot-nemoto/flask-tutorial
- Owner: ot-nemoto
- Created: 2024-03-27T12:30:28.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T10:17:56.000Z (about 2 years ago)
- Last Synced: 2025-01-17T13:35:16.339Z (about 1 year ago)
- Topics: flask, tutorial
- Language: Python
- Homepage: https://msiz07-flask-docs-ja.readthedocs.io/ja/latest/
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# flask-tutorial
## Commands
### データベースファイルの初期化
```sh
flask --app flaskr init-db
```
### アプリケーションの実行
```sh
flask --app flaskr --debug run
```
*http://127.0.0.1:5000/*
### テストの実行
```sh
pip install -e .
pytest -v
```
カバレッジ(網羅率)を測定
```sh
coverage run -m pytest
```
カバレッジリポート
```sh
coverage report
# Name Stmts Miss Branch BrPart Cover
# ------------------------------------------------------
# flaskr/__init__.py 23 0 4 0 100%
# flaskr/auth.py 60 0 30 0 100%
# flaskr/blog.py 58 0 36 0 100%
# flaskr/db.py 23 0 8 0 100%
# ------------------------------------------------------
# TOTAL 164 0 78 0 100%
```
HTMLでカバレッジリポートを出力
```sh
coverage html
```
### ビルド
```sh
python setup.py bdist_wheel
```
### アプリケーションのルート一覧
```sh
flask --app flaskr routes
# Endpoint Methods Rule
# ------------- --------- -----------------------
# auth.login GET, POST /auth/login
# auth.logout GET /auth/logout
# auth.register GET, POST /auth/register
# blog.create GET, POST /create
# blog.delete POST //delete
# blog.detail GET /
# blog.index GET /
# blog.update GET, POST //update
# hello GET /hello
# index GET /
# static GET /static/
```
## 本番環境への展開
インストール
```sh
pip install flaskr-${version}-py3-none-any.whl
```
データベースを作成
```sh
flask --app flaskr init-db
```
秘密鍵の設定
```sh
cat << EOT | tee /home/vscode/.local/var/flaskr-instance/config.py
SECRET_KEY = '$(python -c 'import secrets; print(secrets.token_hex())')'
EOT
```
実行
```sh
pip install waitress
```
```sh
waitress-serve --call 'flaskr:create_app'
```
*http://0.0.0.0:8080*