代码拉取完成,页面将自动刷新
同步操作将从 吕焱飞/QASystem 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import json
import datetime
import hashlib
import time
from urllib.parse import quote, unquote
from answer.MongoUtil import MongoUtil
from util.utils import check_answer_valid, check_question_valid, check_vote
from flask import Flask, render_template, request, redirect
from bson import ObjectId
app = Flask(__name__)
mongo = MongoUtil()
@app.route('/')
def index():
question_list = mongo.query_question()
return render_template('index.html', question_list=question_list)
@app.route('/question')
@app.route('/question/<question_id>')
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})
@app.route('/post_question', methods=['POST'])
def post_question():
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 = question['author']
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
mongo.insert_question(title, detail, author, now)
return json.dumps({'success': True})
@app.route('/vote', methods=['POST'])
def vote():
vote_data = request.json
print(vote_data)
is_valid = check_vote(vote_data)
if not is_valid['success']:
return json.dumps(is_valid)
doc_type = vote_data['doc_type']
value = vote_data['value']
doc_id = vote_data['doc_id']
if doc_type == 'question':
mongo.vote_for_question(doc_id, value)
else:
mongo.vote_for_answer(doc_id, value)
return json.dumps({'success': True})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。