python3: How to use bottle

How to use the framework bottle. I confirmed it on Arch Linux.

Installation

yay python-bottle
yay python-jinja

program

greetings.py


#! /usr/bin/python
#
from bottle import route, run

@route('/hello')
def hello():
	str_out = "Hello World!<br />"
	str_out += "<blockquote>"
	str_out += "Hello.<br />"
	str_out += "</blockquote>"
	str_out += "Nov/11/2020<br />"

	return str_out
#
@route('/morning')
def morning():
	str_out = "Good Morning!<br />"
	str_out += "<blockquote>"
	str_out += "Good morning.<br />"
	str_out += "</blockquote>"
	str_out += "Nov/11/2020<br />"

	return str_out
#
@route('/evening')
def evening():
	str_out = "Good Evening!<br />"
	str_out += "<blockquote>"
	str_out += "tonight.<br />"
	str_out += "</blockquote>"
	str_out += "Nov/11/2020<br />"

	return str_out
#
run(host='localhost', port=8080, debug=True)

Run

$ ./greetings.py 
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.

Access http: // localhost: 8080 / hello with a browser hello.png

Access http: // localhost: 8080 / morning with a browser morning.png

Access http: // localhost: 8080 / evening with a browser evening.png

I confirmed it in the next version.

$ python
Python 3.8.6 (default, Sep 30 2020, 04:00:38) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bottle
>>> print(bottle.__version__)
0.12.18

Recommended Posts

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
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
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 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 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
How to use python-kabusapi
How to use Python zip and enumerate
[Python] Understand how to use recursive functions
How to use OptParse
Summary of how to use Python list