Python
Flask

Flaskのサーバーはデフォルトだと公開されてない

Flask初見で詰まったので、メモを残しておく。

Flaskで最も基本的なサーバー

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello world'

if __name__ == '__main__':
    app.run(debug=False, host='0.0.0.0', port=80)

注意点

host='0.0.0.0' の指定が大事。
これがなければ、外部からアクセスすることができない。
参考: http://flask.pocoo.org/docs/0.12/quickstart/

Externally Visible Server

If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line: