python3: How to use bottle (2)

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 login.png

Recommended Posts

python3: How to use bottle (2)
python3: How to use bottle (3)
python3: How to use bottle
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
How to use Python bytes
Python: How to use async with
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to use python zip function
[Python] How to use Typetalk API
How to use xml.etree.ElementTree
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to use Pandas 2
How to install and use pandas_datareader [Python]
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
[python] How to use __command__, function explanation
How to install python
How to use partial
How to use Bio.Phylo
How to use SymPy
[Python] How to use import sys sys.argv
How to use x-means
How to use WikiExtractor.py
How to use IPython
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
How to use virtualenv
[Python2.7] Summary of how to use unittest
How to use Matplotlib
How to use iptables
python: How to use locals () and globals ()
How to use numpy
How to use __slots__ in Python class
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use "deque" for Python data