代码拉取完成,页面将自动刷新
同步操作将从 xiangfangsong/myFavorite 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- coding: utf-8 -*-
import pymysql
from flask import Flask, request, jsonify
from flask_cors import CORS
#数据库连接
db = pymysql.connect("127.0.0.1","root","123456","myfavorite")
cursor = db.cursor()
#后端服务启动
app = Flask(__name__)
CORS(app, resources=r'/*')
@app.route('/login/list', methods=['POST'])
def login_list():
if request.method == "POST":
cursor.execute("SELECT id,username,role,ctime FROM login")
data = cursor.fetchall();
temp = {}
result = []
if(data!=None):
for i in data:
temp["id"]=i[0]
temp["username"]=i[1]
temp["role"]=i[2]
temp["ctime"]=i[3]
result.append(temp.copy())
print("result: ",len(data))
return jsonify(result)
else:
print("result: NULL")
return jsonify([])
@app.route('/login/add', methods=['POST'])
def login_add():
if request.method == "POST":
username = request.form.get("username")
password = request.form.get("password")
role = request.form.get("role")
try:
cursor.execute("INSERT INTO login(username,password,role) VALUES (\""+str(username)
+"\",\""+str(password)+"\","+str(role)+")")
db.commit()
print("add a new user successfully")
return "1"
except Exception as e:
print("add a new user failed: ",e)
db.rollback()
return "-1"
@app.route('/login/del', methods=['POST'])
def login_del():
if request.method == "POST":
id = request.form.get("id")
try:
cursor.execute("DELETE FROM login WHERE id="+str(id))
db.commit()
print("delete the user successfully")
return "1"
except Exception as e:
print("delete the user failed: ",e)
db.rollback()
return "-1"
@app.route('/login/update', methods=['POST'])
def login_update():
if request.method == "POST":
id = request.form.get("id")
password = request.form.get("password")
try:
cursor.execute("UPDATE login SET password=\""+str(password)+"\" where id="+str(id))
db.commit()
print("update successfully")
return "1"
except Exception as e:
print("update failed: ",e)
db.rollback()
return "-1"
if __name__ == "__main__":
app.run(host='0.0.0.0',port=8899)
db.close()
print("Good bye!")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。