INNER CODE UNIT · Python
update_answer
kingname/SourceCodeofMongoRedis · chapter_12/QASystem/main.py:163
def update_answer(info):
if 'doc_id' not in info or 'text' not in info:
return {'success': False, 'reason': '字段不全,必要字段:doc_id, text'}
mongo.update_answer(info['doc_id'], info['text'])
return {'success': True}
@app.route('/update', methods=['POST'])
def update():
session_data = redis.fetch_session(request.cookies.get('session'))
if not session_data:
return json.dumps({'success': False, 'reason': '未登录!'})
info = request.json
update_type = info.get('update_type')
if update_type == 'question':
return json.dumps(update_question(info))
elif update_type == 'answer':
return json.dumps(update_answer(info))