最近,趁着假期,复习了一遍以前学习到的python知识,和研究新的web框架Bottle,就写了个简单的登录页面,详细可以参考官方文档http://bottle.zzir.cn/
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
from bottle import request, route, run, template
@route('/login', method='POST')
def do_login():
username = request.forms.get('username')
password = request.forms.get('password')
print (username, password)
if username == 'admin' and password == 'admin':
return username + '登录成功'
else:
return username + '登陆失败'
#用户登录
@route('/index')
def index():
return template('index')
run(host='0.0.0.0', port=9090, debug=True)
前端代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>login</title> </head> <body> <form action='/login' method='POST'> 用户名:<input type="text" name="username" /> 密码:<input type="password" name="password" /> </br><input type="submit" value='login'/> </form> </body> </html>
最后,运行的结果是这样的:
转载于:https://blog.51cto.com/1238306/1930654