flask-classy での Web サーバ作成のメモ。
■test_api_view.py
■test.py
■実行結果
■test_api_view.py
from flask import Flask from flask_classy import FlaskView class TestApiView(FlaskView): def index(self): return "index() is called\n" def search(self): return "search() is called\n"
■test.py
from flask import Flask from flask_classy import FlaskView from test_api_view import TestApiView def main(): app = Flask(__name__) TestApiView.register(app) app.run() return 0 if __name__ == '__main__': res = main() exit(res)
■実行結果
curl "http://localhsot:5000/testapi/" index() is called curl "http://localhost:5000/testapi/search/" search() is called