INNER CODE UNIT · Python
post_question
kingname/SourceCodeofMongoRedis · chapter_11/QASystem/main.py:95
def post_question():
session_data = redis.fetch_session(request.cookies.get('session'))
if not session_data:
return json.dumps({'success': False, 'reason': '未登录!'})
question = request.json
is_valid = check_question_valid(question)
if not is_valid['success']:
return json.dumps(is_valid, ensure_ascii=False)
title = question['title']
detail = question['detail']
author = session_data['user']
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
doc_id = mongo.insert_question(title, detail, author, now)
return json.dumps({'success': True, 'doc_id': doc_id})
def update_question(info):
if 'doc_id' not in info or 'title' not in info or 'text' not in info: