INNER CODE UNIT · Python
question_detail
kingname/SourceCodeofMongoRedis · chapter_10/QASystem/main.py:23
def question_detail(question_id=None):
if question_id:
question_answer_dict = mongo.query_answer(question_id)
return render_template('answer_list.html', question_answer_dict=question_answer_dict)
@app.route('/post_answer', methods=['POST'])
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})