在python中Flask配置服务
Posted wdan2016
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在python中Flask配置服务相关的知识,希望对你有一定的参考价值。
from flask import Flask, request
from data_util import UtilsLTPTranslate
import json
model = UtilsLTPTranslate()
app = Flask(name)
@app.route("/")
def index():
return "翻译服务: 运行中"
@app.route("/LTPTranslate", methods=[‘POST‘, ‘GET‘])
def code():
text = request.form[‘text‘]
response = {}
data=[]
try:
if request.form[‘flag‘] == ‘companyName‘:
data.append(model.getEnCompanyName(text))
elif request.form[‘flag‘] == ‘address‘:
data.append(model.getEnAddress_2(text))
elif request.form[‘flag‘] == ‘common‘:
data.append(model.zh2en(text))
else:
data.append(model.zh2en(text))
response["data"] = data
except:
response["data"] = data
return json.dumps(response, ensure_ascii=False)
if name == ‘main‘:
app.run(host="0.0.0.0", port="8005",processes=200)
以上是关于在python中Flask配置服务的主要内容,如果未能解决你的问题,请参考以下文章