from flask import Flask, request, jsonify
from pymongo import MongoClient
app = Flask(__name__)
client = MongoClient('mongodb://localhost:27017/')
db = client['teacher_info']
teachers_collection = db['teachers']
topics_collection = db['topics']
# 上传课题接口
@app.route('/upload_topic', methods=['POST'])
def upload_topic():
data = request.get_json()
topic_id = topics_collection.insert_one(data).inserted_id
return jsonify({'message': 'Topic uploaded successfully', 'topic_id': str(topic_id)})
# 分配课题给教师接口
@app.route('/assign_topic', methods=['POST'])
def assign_topic():
data = request.get_json()
teacher_id = data.get('teacher_id')
topic_id = data.get('topic_id')
teachers_collection.update_one({'_id': teacher_id}, {'$set': {'topic_id': topic_id}})
return jsonify({'message': 'Topic assigned to teacher successfully'})
# 修改课题接口
@app.route('/update_topic/<topic_id>', methods=['PUT'])
def update_topic(topic_id):
data = request.get_json()
topics_collection.update_one({'_id': topic_id}, {'$set': data})
return jsonify({'message': 'Topic updated successfully'})
# 获取所有教师及其课题信息接口
@app.route('/get_all_teachers_topics', methods=['GET'])
def get_all_teachers_topics():
teachers = teachers_collection.find()
result = []
for teacher in teachers:
topic_id = teacher.get('topic_id')
topic = topics_collection.find_one({'_id': topic_id})
result.append({'teacher': teacher, 'topic': topic})
return jsonify(result)
if __name__ == '__main__':
app.run(host='your_host_IP',port=1111)
基于Flask+MongoDB+HTML的一个课题管理程序
99 浏览量
2024-02-28
00:02:41
上传
评论
收藏 1KB RAR 举报
IRUIRUI__
- 粉丝: 525
- 资源: 55
最新资源
- Python爬取淘宝热卖商品并可视化分析
- 5152单片机proteus仿真和源码将按键次数写入AT24C02再读出并用1602LCD显示
- SE-SSD复现过程(Det3D的安装教程)
- 基于Python的在线学习与推荐系统设计与实现(论文+源码)-kaic
- 串口通过 YMODEM 协议进行文件传输
- 蓝桥杯2024年第十五届省赛真题-前缀总分
- com.qihoo.appstore_300101305-1.apk
- tensorflow-gpu-2.7.1-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.1-cp39-cp39-manylinux2010-x86-64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈