I made it possible to execute the snippet here. This is a sample login. Docs »Tutorial
login.py
#! /usr/bin/python
#
# login.py
#
# Nov/11/2020
# ------------------------------------------------------------------
from bottle import get, post, request, run
#
def check_login(name,password):
rvalue = True
if name != password:
rvalue = False
return rvalue
#
# ------------------------------------------------------------------
@get('/login') # or @route('/login')
def login_form():
str_out = '<form method="POST" action="/login">'
str_out += '<input name="name" type="text" />'
str_out += '<input name="password" type="password" />'
str_out += '<input type="submit" />'
str_out += '</form>'
return str_out
#
# ------------------------------------------------------------------
@post('/login') # or @route('/login', method='POST')
def login_submit():
name = request.forms.get('name')
password = request.forms.get('password')
if check_login(name, password):
return "<p>*** Your login was correct ***</p>"
else:
return "<p>*** Login failed ***</p>"
#
# ------------------------------------------------------------------
run(host='localhost', port=8080, debug=True)
#
# ------------------------------------------------------------------
Server execution
$ ./login.py
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
In your browser, http: // localhost: 8080 / login Access to
Recommended Posts