app.py
from bottle import route, run
from bottle import TEMPLATE_PATH, jinja2_template as template
TEMPLATE_PATH.append("./views")
@route('/')
@route('/hello/<name>')
def greet(name="Stranger"):
return template('hello.j2', name=name)
run(host='localhost', port=8080, debug=True, reloader=True)
The source is as above (development environment).
For your reference
hello.j2
{% extends "base.j2" %}
{% block content %}
Hello {{ name }}! How are you?
{% endblock %}
base.j2
<html>
<head>
<title> Sample Bottle App </title>
</head>
<body>
{% block content %} {% endblock %}
</body>
</html>
Run the server on
% python app.py
http://localhost:8080/ When http://localhost:8080/hello/hoge When you access, you can see that the screen is output correctly with both defaults and parameters.
Recommended Posts