0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Flask Practices #1, cookiecutter-flask を用いたプロジェクトの新規作成

Last updated at Posted at 2019-07-20

目次 | 次回>>>

概要

flask のプロジェクトを flask-cookiecutter を使って楽にスマートに新規作成する方法です。

内容

Flask プロジェクトの初期コード生成を生成します。
python のパッケージ管理には pipenv を選択するケースです。
プロジェクト名は panels としました。

cookiecutterでプロジェクト生成
> pipenv install
...
Successfully created virtual environment!
Virtualenv location: %VIRTUALENV_PATH%
> pipenv shell
> pipenv install cookiecutter
> pipenv run pip freeze
arrow==0.14.2
binaryornot==0.4.4
certifi==2019.6.16
chardet==3.0.4
Click==7.0
cookiecutter==1.6.0
future==0.17.1
idna==2.8
Jinja2==2.10.1
jinja2-time==0.2.0
MarkupSafe==1.1.1
poyo==0.4.2
python-dateutil==2.8.0
requests==2.22.0
six==1.12.0
urllib3==1.25.3
whichcraft==0.6.0
>
> cookiecutter https://github.com/cookiecutter-flask/cookiecutter-flask.git
full_name [Steven Loria]: YOURNAME
email [sloria1@gmail.com]: YOURNAME@example.com
github_username [sloria]: YOURNAME
project_name [My Flask App]: Web Panels
app_name [web_panels]: panels
project_short_description [A flasky app.]: panels app.
Select use_pipenv:
1 - no
2 - yes
Choose from 1, 2 (1, 2) [1]: 2
Select python_version:
1 - 3.7
2 - 3.6
Choose from 1, 2 (1, 2) [1]: 1
Select node_version:
1 - 12
2 - 10
3 - 8
Choose from 1, 2, 3 (1, 2, 3) [1]: 2
>
> exit
> ls -Name
panels           # ここ配下がPJROOT
Pipfile          # これは用済み
Pipfile.lock     # これは用済み
> exit
> pipenv --rm    # 用済みの仮想環境は抹消
> rm .\Pipenv*
> cd ${workspaceFolder}
> pwd

Path
----
${workspaceFolder}
restructuredtextを個人的に慣れてるmarkdownに変換。本題じゃないです
${workspaceFolder}> .\pandoc -f rst -t gfm -o readme.md README.rst
${workspaceFolder}> rm README.rst
リポジトリへpush
${workspaceFolder}> git init
${workspaceFolder}> git add .
${workspaceFolder}> git commit -m "first commit"
${workspaceFolder}> git remote add origin https://github.com/*.git
${workspaceFolder}> git push -u origin master

今回はここまで。次回は初回起動してみます。

cookiecutter とは

Flask で初めて Webapp を作る際に、Boilerplate に割く時間を減らしたいけど、ベストプラクティスはある程度取り込んでおきたい。んで、知識やニーズが増えてきて、規模とライフサイクルが長いアプリを作ろうと思った時にも、大幅に設計思想を変えずに転用できるノウハウやコードを初めから利用したい。といった時には、*-cookiecutter-* というテンプレが優秀です。Flask だけでなく、他フレームワーク(Djangoとか)でも用意されてます。

Features にはこんな風に書いています。

  • Bootstrap 4 and Font Awesome 4 with starter templates
  • Flask-SQLAlchemy with basic User model
  • Easy database migrations with Flask-Migrate

・・・

私は、以下の要素が良いと思いました。cookiecutter-flask は Features の各要素が必要・役に立つと分かる場合や、動作やお手本をまず見てみたい場合はいいサンプルです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?