python
from bottle import route, run
@route('/hello')
def hello():
return "Hello, World!"
run(host='localhost', port=8080)
python
from bottle import route, template, run
@route('/hello/<name>')
def hello(name):
return template('hello_template', name=name)
run(host='localhost', port=8080)
html
<!DOCTYPE html>
<html>
<head>
<title>Hello {{name}}</title>
</head>
<body>
<h1>Hello {{name}}</h1>
</body>
</html>
python
from bottle import route, run, template
import sqlite3
@route('/users')
def get_users():
connection = sqlite3.connect('database.db')
cursor = connection.cursor()
cursor.execute("SELECT * FROM users")
users = cursor.fetchall()
connection.close()
return template('users_template', users=users)
run(host='localhost', port=8080)
python
from bottle import route, run, request
def log_middleware(callback):
def wrapper(*args, **kwargs):
print("Request Received:", request.method, request.path)
return callback(*args, **kwargs)
return wrapper
@route('/hello')
@log_middleware
def hello():
return "Hello, World!"
run(host='localhost', port=8080)