2
0

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 1 year has passed since last update.

【Flask】5分で仮想環境構築と「Hello World!」の表示

Last updated at Posted at 2021-09-12

環境

  • Microsoft Windows 10.0.19042.1165
  • Python 3.9.4
  • Flask 1.1.2

ディレクトリ構成

flask_test/
  ├─ venv/
  └─ app.py

手順

Pythonはインストール済みとする

仮想環境用ディレクトリ flask_test を作成( mkdir [フォルダ名]

mkdir flask_test

flask_test に移動( cd [フォルダ名]

cd flask_test

仮想環境を作成( python -m venv ./[フォルダ名]

python -m venv ./venv

仮想環境を有効化( [フォルダ名]\Scripts\activate

venv\Scripts\activate

→ 先頭に (env) が付く

無効化するときは「deactivate」と入力

仮想環境の中にFlaskをインストール

pip install Flask

flask_test フォルダの中に app.py を作成

app.py
from flask import Flask
app = Flask(__name__)

@app.route("/")
def index():
    return "Hello World!"

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

実行する

Flask run

http://localhost:5000/ にアクセスすると"Hello World!"と表示される

ちなみに

以下のように入力すると requirements.txt に現在の環境(設定)を書き出すことができる

pip freeze > requirements.txt
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?