1
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?

Flask runが実行できない(アプリが起動しない)

Last updated at Posted at 2024-05-16

本日のお悩み

flaskアプリを作成しflask runを実行しても起動しない
以下のエラーが発生

> flask run
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
# エラーが発生しました。Flask アプリケーションが見つかりませんでした。環境変数 "FLASK_APP "が指定されておらず、カレントディレクトリに "wsgi.py "または "app.py "モジュールが見つかりませんでした。

実行するアプリを認識できていないため起動できない模様

本日の処方箋

FLASK_APPという環境変数にアプリケーション名を設定する
(ただしapp.pyかwsgi.pyならFLASK_APPが設定されていなくても実行される。)

環境変数を再設定

> export FLASK_APP=sample.py

もう一度実行

> flask run

* Serving Flask app 'sample.py' (lazy loading)
* Environment: production
  WARNING: This is a development server. Do not use it in a production deployment.
  Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

無事起動しました。http://127.0.0.1:5000/へアクセスして動作確認

そもそもflask runしなくても起動する方法

flask run しなくても起動はできます。

 > python sample.py
 
 * Serving Flask app "sample" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   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: 269-498-948
1
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
1
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?