3
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 5 years have passed since last update.

flaskアプリを、pdbを活用してデバッグする方法

Last updated at Posted at 2019-06-21

#手順
stack overflowのDebugging flask with pdbを参考にしています。

  1. screenなどを使って2つ端末を立ち上げておきます。以降端末1、端末2と書きます。

  2. flaskアプリ上のデバッグを開始したい箇所に、次のコードを埋め込みます。

    import pdb; pdb.set_trace()
    
  3. 端末1で、flaskのdevelopment用サーバをflask runにて起動します。下のようにFLASK_ENVを設定するとデバッグ出力モードになります。(参考:flask Development Server

    $ export FLASK_ENV=development
    $ flask run
    
  4. この状態のまま、端末2で、curlコマンドで該当のアプリにアクセスします。
    なお、curlの使い方は「curlコマンドの使い方 ~GET、POST、REST(json)の確認と、windowsでの利用手順」が分かりやすく参考になりました。

  5. そうすると、端末2(curl側)では待機状態になっているはずです。このまま端末1(flask側)を見るとpdbに入っていますので、後は端末1側でpdbにてデバッグすることができます。

#環境
次でできました。難しい仕組みを使っていないので、広く活用できると思います。
flask: 1.0.2
python: 3.7.3
サーバ側のOS: linux(CentOS7)
#最後に
pdbはシンプルで便利なので、flaskアプリでもpdbでデバッグができて幸せでした。

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