Google Colabでflaskのサンプルプログラムを実行しました。
下記がコードです。
python
1from flask import Flask 2 3app = Flask(__name__) 4 5@app.route('/') 6def hello_world(): 7 return 'hello_world' 8 9def main(): 10 app.debug = True 11 app.run() 12 13if __name__ == '__main__': 14 main()
これを実行すると下記警告文がでてきます。
- Serving Flask app "main" (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
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py:2890: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
この後、http://127.0.0.1:5000/ リンク先に行こうとすると
このサイトにアクセスできません127.0.0.1 で接続が拒否されました。
とでてしまいます。
上記コードをターミナルから実行した場合は、
- Serving Flask app "flask_test" (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
- Restarting with stat
- Debugger is active!
- Debugger PIN: 148-584-338
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
と表示され、リンク先に飛ぶと、hello_world が表示されます。
colab上で実行できるようにするにはどのようにしたら良いのでしょうか?
ご教授頂けますよう、宜しくお願い致します。