Here is a template code for creating a simple HTML app with Bottle.
from bottle import route, run, view, debug
@route('/')
@view('index')
def index():
return {}
if __name__ == '__main__':
debug(True)
run(host='127.0.0.1', port=8080, reloader=True)
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<title>{{ title or 'default title' }}</title>
</head>
<body>
<header class="bg-dark">
<div class="p-2">
<a href="/" class="text-white h3 m-0 text-decoration-none">
Site Title
</a>
</div>
</header>
{{!base}}
</body>
</html>
% rebase('base.tpl', title='Page Title')
<p>This is index content</p>
When combining Bottle with Vue CDN, you can build a simple feature app very quickly and with minimal code.
This is sufficient if it's a tool only used by yourself or an app used within a limited team in a LAN environment.
from bottle import route, run, view, debug, StplParser
@route('/')
@view('index')
def index():
return {}
if __name__ == '__main__':
debug(True)
StplParser.default_syntax = '<% %> % [[ ]]'
run(host='127.0.0.1', port=8080, reloader=True)
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<title>[[ title or 'default title' ]]</title>
<style>
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<header class="bg-dark">
<div class="p-2">
<a href="/" class="text-white h3 m-0 text-decoration-none">
Site Title
</a>
</div>
</header>
[[!base]]
</body>
</html>
% rebase('base.tpl', title='Page Title')
<div id="app" v-cloak>
<p>{{ message }}</p>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
data() {
return {
message: '',
};
},
methods: {
...
}
})
app.mount('#app')
</script>
Bottle Documentation: https://bottlepy.org/docs/dev/index.html
Comments