From 650d8c33615618889f5ddec422f29641b68d1f9c Mon Sep 17 00:00:00 2001 From: p73692015 Date: Tue, 9 Jan 2024 21:11:45 +0800 Subject: [PATCH] ADD file via upload --- app.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..2bc5ca3 --- /dev/null +++ b/app.py @@ -0,0 +1,29 @@ +# backend/app.py +from flask import Flask, request, jsonify + +from flask_cors import * + +app = Flask(__name__) +CORS(app, supports_credentials=True) + +todos = [] + +@app.route("/") +def hello(): + return "Hello, World!" +@app.route("/todos", methods=["GET"]) +def get_todos(): + return jsonify(todos) +@app.route("/todos", methods=["POST"]) +def add_todo(): + todo = request.json + todos.append(todo) + return jsonify(todo), 201 +@app.route("/todos/", methods=["DELETE"]) +def delete_todo(index): + if index < len(todos): + deleted_todo = todos.pop(index) + return jsonify(deleted_todo) + return "", 404 +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file