加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TestServer.py 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
福叔攒钱买房车 提交于 2018-05-06 20:32 . 第二次教学
from flask import Flask,render_template,jsonify,request
from random import randint
app = Flask(__name__)
def rand_five_percent():
rel = randint(1,5)
if rel ==5:
return True
return False
def rand_ten_percent():
rel = randint(1,10)
if rel == 5:
return True
return False
def rand_fiften_percent():
rel = randint(1,15)
if rel == 5:
return True
return False
def rand_twenty_percent():
rel = randint(1,20)
if rel == 5:
return True
return False
@app.route("/")
def index():
for x in range(10000):
rand_five_percent()
return "ok"
@app.route("/api/test/probability")
def random_app():
value = request.values
amount = value.get("amount")
data = {
"status":True
}
try:
amount = int(amount)
except Exception as e:
data["status"] = False
data["err_msg"] = e.args
return jsonify(data)
if amount<500:
rel = rand_five_percent()
elif amount >= 500 and amount< 1000:
rel = rand_ten_percent()
elif amount >1000 and amount <2000:
rel = rand_fiften_percent()
else:
rel = rand_twenty_percent()
data["data"] = {
"win":rel
}
return jsonify(data)
@app.route("/api/login")
def login_func():
forms = request.values
username = forms.get("username")
password = forms.get("password")
print(username)
print(password)
if username=="wo" and password == "ni":
return jsonify({"status":True})
else:
return jsonify({"status":False})
@app.route("/api/login2",methods=["POST","GET"])
def login_func2():
if request.method == "POST":
forms = request.values
username = forms.get("username")
password = forms.get("password")
print(username)
print(password)
if username=="wo" and password == "ni":
return jsonify({"status":True})
else:
return jsonify({"status":False})
elif request.method == "GET":
return jsonify({"status":False,"err_msg":"请求不合法"})
if __name__ == "__main__":
app.run(host="0.0.0.0",port=8800,debug=True)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化