Ich habe es möglich gemacht, das Snippet hier auszuführen. Dies ist ein Beispiel-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)
#
# ------------------------------------------------------------------
Führen Sie den Server aus
$ ./login.py
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
In Ihrem Browser http: // localhost: 8080 / login Zugriff auf
Recommended Posts