配置路由、swagger、wsgi

This commit is contained in:
huangge1199 2025-06-25 11:32:10 +08:00
parent eafc1f5eda
commit 0b19e2572d
5 changed files with 41 additions and 3 deletions

16
app.py
View File

@ -1,12 +1,22 @@
from flask import Flask from flask import Flask
from flasgger import Swagger
from flask_cors import CORS
app = Flask(__name__) app = Flask(__name__)
CORS(app)
swagger = Swagger(app)
@app.route('/') @app.route('/')
def hello_world(): # put application's code here def hello_world():
"""
一个hello world 的测试
---
responses:
200:
description: 返回值
"""
return 'Hello World!' return 'Hello World!'
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run(debug=True, port=18080)

13
app/__init__.py Normal file
View File

@ -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

8
app/routes.py Normal file
View File

@ -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!"})

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
flask
flask-cors
flasgger

4
wsgi.py Normal file
View File

@ -0,0 +1,4 @@
from app import app
if __name__ == "__main__":
app.run()