Help us understand the problem. What is going on with this article?

はじめてのFlask - Hello World -

More than 1 year has passed since last update.

流れでFlask使い始めたけど、
一から作って見ないとわからないと思ったので、

とりあえずおきまりの。

Hello World

http://flask.pocoo.org/

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

@app.route('/')
def hello():
    return "Hello, World!"              

$ FLASK_APP=main.py flask run
ポートはデフォルトで5000だそうなので、
$ curl http://0.0.0.0:5000/
Hello, World!

ほなおっけー。
ちょっと改変して

場合分け

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

@app.route('/')
def hello():
    return "Hello, World!"
@app.route('/Japan')
def hello2():
    return "Hello, Japan!"

$ curl http://0.0.0.0:5000/
Hello, World!
$ curl http://0.0.0.0:5000/Japan
Hello, Japan!

場合分けはそういう感じね。
でも run めんどくさい...
main に書けばいいのね
https://a2c.bitbucket.io/flask/tutorial/setup.html?highlight=run

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

@app.route('/')
def hello():
    return "Hello, World!"
@app.route('/Japan')
def hello2():
    return "Hello, Japan!"

if __name__ == '__main__':
    app.run()

外部アクセス

あと、デフォルは立てたサーバーは自分のコンピューターからしかアクセスできないそうで、
外部から見たいときは単純に
app.run(host='0.0.0.0')
とすればいいそうで。

終わりに

細かいところはこれから詰めて行きます。悪しからず。

ごちそうさまでした。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした