?? ??, ?? ??, ?? ??? ??? ? ?? server.py ??? ??????. client.html ??? ???? ???? ??? ? ?? ??? ???? ??? ????? ?????? ????? ?? ???? ??? ???? ?? ??? ???? 404 Student Not Found?? ?????. p>
server.py ?? ??? ??? ????.
????client.html ?? ??? ??? ????.
from flask import Flask, request, jsonify import pickle app = Flask(__name__) try: with open('students.pickle', 'rb') as f: students = pickle.load(f) except FileNotFoundError: students = {} @app.route("/") def index(): with open("client.html") as f: return f.read() @app.route('/add_student', methods=['POST']) def add_student(): name = request.form.get('name') surname = request.form.get('surname') index = request.form.get('index') grade = request.form.get('grade') students[index] = {'name': name, 'surname': surname, 'index': index,'grade': grade} with open('students.pickle', 'wb') as f: pickle.dump(students, f) return jsonify(message='Student added successfully'), 201 @app.route('/get_student/<int:index>', methods=['GET']) def get_student(index): student = students.get(index) if student: return jsonify(student) else: return 'Student not found', 404 if __name__ == '__main__': app.run(host='localhost', port=8000, debug=True)
html ????? ? ??(?? ?? ?? ? ???? ??)? ??? ID? ???? ??? ??? ? ?? ??? ????. ??? ??? ??? " "? ?? ??? ?? ?? ? ????. .
EDIT: ? ?? ??? ???? ?????? ?? get ????? ?????? ??? ????. [?? index = str(index) ???]
??? ?? ????.