#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2016-05-18 18:16:35 # @Author : PiaoYun(piaoyunsoft@163.com) # @Link : http://www.dllhook.com # @Version : 1.0.0 from flask import Flask from flaskext.mysql import MySQL import json app = Flask(__name__) mysql = MySQL() app.config['MYSQL_DATABASE_USER'] = 'root' app.config['MYSQL_DATABASE_PASSWORD'] = 'root' app.config['MYSQL_DATABASE_DB'] = 'debug' app.config['MYSQL_DATABASE_HOST'] = '127.0.0.1' mysql.init_app(app) def GetUserInfo(username): conn = mysql.connect() cur = conn.cursor() cur.execute("select * from user where username='%s'" % username); data = cur.fetchone() if len(data): return json.dumps({"id":str(data[0]), "name":username}) else: return json.dumps({"error":"Not found"}) @app.route('/api/user/<username>', methods=['GET']) def UserInfo(username): return GetUserInfo(username) @app.route('/') def hello(): return 'Hello PiaoYun' if __name__=='__main__': app.run(debug=True)
发表评论