From 0b19e2572dfbbf66542a3c3d46448207a4381d67 Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Wed, 25 Jun 2025 11:32:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B7=AF=E7=94=B1=E3=80=81sw?= =?UTF-8?q?agger=E3=80=81wsgi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 16 +++++++++++++--- app/__init__.py | 13 +++++++++++++ app/routes.py | 8 ++++++++ requirements.txt | 3 +++ wsgi.py | 4 ++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/__init__.py create mode 100644 app/routes.py create mode 100644 requirements.txt create mode 100644 wsgi.py diff --git a/app.py b/app.py index 5d20a01..7dc8bc0 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,22 @@ from flask import Flask +from flasgger import Swagger +from flask_cors import CORS app = Flask(__name__) - +CORS(app) +swagger = Swagger(app) @app.route('/') -def hello_world(): # put application's code here +def hello_world(): + """ + 一个hello world 的测试 + --- + responses: + 200: + description: 返回值 + """ return 'Hello World!' if __name__ == '__main__': - app.run() + app.run(debug=True, port=18080) diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..5c2adfd --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,13 @@ +from flask import Flask +from flask_cors import CORS +from flasgger import Swagger + +def create_app(): + app = Flask(__name__) + CORS(app) + swagger = Swagger(app) + + from .routes import bp as main_bp + app.register_blueprint(main_bp) + + return app diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..df54931 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,8 @@ +from flask import Blueprint, jsonify + +bp = Blueprint('main', __name__) + +@bp.route('/api/hello', methods=['GET']) +def hello(): + return jsonify({"message": "Hello from Flask!"}) + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..de58312 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask +flask-cors +flasgger \ No newline at end of file diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..6026b0f --- /dev/null +++ b/wsgi.py @@ -0,0 +1,4 @@ +from app import app + +if __name__ == "__main__": + app.run()