flask
运行
$export FLASK_APP=hello.py
$export FLASK_ENV=development
$flask run --host=0.0.0.0
# win
python -m flask run -h 0.0.0.0 -p 5000
# linux
flask run --host=0.0.0.0 --port=5001
Route
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello')
def hello():
return 'Hello, World'
Blueprint
app/
|
├── app.py
└── example_blueprint.py
example_blueprint.py
from flask import Blueprint
example_blueprint = Blueprint('example_blueprint', __name__)
@example_blueprint.route('/')
def index():
return "This is an example app"
app.py
from flask import Flask
from example_blueprint import example_blueprint
app = Flask(__name__)
app.register_blueprint(example_blueprint)