python 连接数据库条件查询2
from flask import Flask, request import os import json import pymysql os.environ[‘NLS_LANG‘] = ‘SIMPLIFIED CHINESE_CHINA.UTF8‘ app = Flask(__name__) @app.route(‘/index1‘, methods=[‘POST‘]) def indextest(): inputData = request.json.get(‘inputData‘) data1 = getcontent(inputData) return data1 def getcontent(inputData): conn = pymysql.connect( host="172.0.0.0", port=8888, user="test", password="pwd", database="table", charset="utf8") cur = conn.cursor() sql = "SELECT account,name,passwd FROM table where name=‘%s‘"%(inputData) cur.execute(sql) data = cur.fetchone() print(data) # para = [] # for i in data: # text = {‘account‘: i[0], ‘username‘: i[1], ‘password‘: i[2]} # # print(text) # para.append(text) result = {‘account‘: data[0], ‘username‘: data[1], ‘password‘: data[2]} return json.dumps(result, ensure_ascii=False, indent=4) if __name__ == ‘__main__‘: app.run(host=‘127.0.0.4‘, port=5590)
通过输入参数,返回自己想要的结果
相关推荐
夜斗不是神 2020-11-17
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16