INNER CODE UNIT · Python
post_answer
kingname/SourceCodeofMongoRedis · chapter_10/QASystem/main.py:30
def post_answer():
answer = request.json
is_valid = check_answer_valid(answer)
if not is_valid['success']:
return json.dumps(is_valid, ensure_ascii=False)
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
question_id = answer['question_id']
author = answer['author']
answer = answer['answer']
mongo.insert_answer(question_id, answer, author, now)
return json.dumps({'success': True})
@app.route('/post_question', methods=['POST'])
def post_question():
question = request.json
is_valid = check_question_valid(question)
if not is_valid['success']: