フレームワーク bottle の使い方です。
Arch Linux でのインストール
yay python-bottle
yay python-jinja
Ubuntu 22.04 でのインストール
sudo apt install python3-bottle
プログラム
greetings.py
#! /usr/bin/python
#
from bottle import route, run
@route('/hello')
def hello():
str_out = "Hello World!<br />"
str_out += "<blockquote>"
str_out += "こんにちは。<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 += "おはようございます。<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 += "今晩は。<br />"
str_out += "</blockquote>"
str_out += "Nov/11/2020<br />"
return str_out
#
run(host='localhost', port=8080, debug=True)
実行
$ ./greetings.py
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
ブラウザーで http://localhost:8080/hello にアクセス
ブラウザーで http://localhost:8080/morning にアクセス
ブラウザーで http://localhost:8080/evening にアクセス
次のバージョンで確認しました。
$ python
Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bottle
>>> print(bottle.__version__)
0.12.19