ADD file via upload

This commit is contained in:
p73692015 2024-01-09 21:11:45 +08:00
parent 4fc06b5d6e
commit 650d8c3361
1 changed files with 29 additions and 0 deletions

29
app.py Normal file
View File

@ -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/<int:index>", 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)