最近,趁着假期,複習了一遍以前學習到的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>
最後,運行的結果是這樣的: