#vim api.py
#!/bin/env python
#-*- coding:utf-8 -*-
#****************************************************************#
# ScriptName: api.py
# Author:berlin
# Create Date:2013-07-25
# Modify Author:
# Modify Date:
# Function:用webpy实现对外API接口
#****************************************************************#
import web
urls = (
'/(.*)/(.*)', 'api',
)
class api:
def GET(self, user, password):
if user:
conn = web.database(dbn='mysql', user='root', pw='123456', db='weibo')
cur = conn.query("select password from auth_user where username = '%s'" % user)
pw = cur.list()[0]['password']
if password == pw:
return 'ok'
else:
return 'false'
else:
return 'User Not exist'
if __name__ == "__main__":
app = web.application(urls, globals())
#print globals()
app.run()
#python api.py 默认启动8080端口,也可以手动指定端口例如:python api.py 80
测试:
在浏览器地址栏中输入:
页面会返回验证的结果
阅读(2313) | 评论(0) | 转发(0) |