INNER CODE UNIT · Python
question_detail
kingname/SourceCodeofMongoRedis · chapter_11/QASystem/main.py:62
def question_detail(question_id=None):
session_data = redis.fetch_session(request.cookies.get('session'))
question_answer_dict = mongo.query_answer(question_id)
could_answer_this_question = True
if 'user' not in session_data or redis.check_user_answer_question(session_data['user'], question_id):
could_answer_this_question = False
session_data['could_answer_this_question'] = could_answer_this_question
return render_template('answer_list.html', question_answer_dict=question_answer_dict, session=session_data)
@app.route('/post_answer', methods=['POST'])
def post_answer():
session_data = redis.fetch_session(request.cookies.get('session'))
if not session_data:
return json.dumps({'success': False, 'reason': '未登录!'})
answer = request.json