Verwendung der Vorlage.
Ordnerstruktur
$ tree
.
├── template.py
└── views
└── sample.html
template.py
#! /usr/bin/python
#
# template.py
#
# Nov/12/2020
#
# ------------------------------------------------------------------
from bottle import run, route, template
# ------------------------------------------------------------------
@route("/")
def index():
username = 'Natsume Soseki'
return template('sample', username=username)
# ------------------------------------------------------------------
@route('/hello/<name>')
def hello(name="Stranger"):
return template("Hello, {{ name }}. How are you?", name=name)
# ------------------------------------------------------------------
if __name__ == "__main__":
run(host='localhost', port=8080, reloader=True, debug=True)
# ------------------------------------------------------------------
views/sample.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<title>Template Engine</title>
</head>
<body>
<h2>Hallo: {{ username }}</h2>
Nov/12/2020<br />
</body>
</html>
Führen Sie den Server aus
$ ./template.py
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
Zugriff durch Client http://localhost:8080/
http://localhost:8080/hello/太郎
Recommended Posts