Python使用flask获取Post和get请求

@app.route('/company_qa', methods=['POST', 'GET'])
def company_qa_login():
	"""
	公司问答的请求代码
	:return:
	"""
	starttime = datetime.datetime.now()
	if request.method == 'POST':
		#读取form类型数据
		formData = request.form
		formDict = formData.to_dict()
		print(formDict)
		resp = jsonify({'answer': qa(formDict['question'], alice,model,id_question)})
		resp.headers['Access-Control-Allow-Origin'] = '*'
		endtime = datetime.datetime.now()
		print(endtime - starttime)
		return resp
	elif request.method == 'GET':
		print(request.args["question"])
		resp = jsonify({'answer': qa(request.args["question"], alice, model, id_question)})
		resp.headers['Access-Control-Allow-Origin'] = '*'
		endtime = datetime.datetime.now()
		print(endtime - starttime)
		return resp
	else:
		resp = jsonify({'answer': "对不起,您的问题暂时不能回答"})
		resp.headers['Access-Control-Allow-Origin'] = '*'
		return resp

程序员有偿接单和程序指导加QQ:734564390 

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页