0
1

More than 1 year has passed since last update.

python3: bottle の使い方

Last updated at Posted at 2020-11-11

フレームワーク 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 にアクセス
hello.png

ブラウザーで http://localhost:8080/morning にアクセス
morning.png

ブラウザーで http://localhost:8080/evening にアクセス
evening.png

次のバージョンで確認しました。

$ 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
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1