python web 開發框架之Bottle

最近,趁着假期,複習了一遍以前學習到的python知識,和研究新的web框架Bottle,就寫了個簡單的登錄頁面,詳細可以參考官方文檔http://bottle.zzir.cn/


不廢話,直接上截圖和代碼:
wKioL1ksdRqATi5EAAEcUWNT8U8484.png-wh_50

代碼如下:

#!/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>


最後,運行的結果是這樣的:

wKioL1ksdcqiF1nJAAAW41gC8fI356.png-wh_50

wKiom1ksdcvDqcTwAAAWv7uSPDY808.png-wh_50


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章