Skip to content

Instantly share code, notes, and snippets.

@pauleveritt
Created May 22, 2020 14:11
Show Gist options
  • Save pauleveritt/8625dff5436f1a6b8b9e4b6785034155 to your computer and use it in GitHub Desktop.
Save pauleveritt/8625dff5436f1a6b8b9e4b6785034155 to your computer and use it in GitHub Desktop.
Try 2
from os.path import abspath, dirname, join
from examples.usage.csr.bottle import route, run, static_file, template
STATIC_DIR = abspath(join(dirname(__file__), 'static'))
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root=STATIC_DIR)
@route('/')
def index():
return '''
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello Bulma!</title>
<link rel="stylesheet" href="static/bulma.css">
</head>
<body>
<section class="section">
<div class="container">
<h1 class="title">
Hello World
</h1>
<p class="subtitle">
My first website with <strong>Bulma</strong>!
</p>
</div>
</section>
<script type="module">
import { render, createElement } from 'https://unpkg.com/preact?module';
function create(h, json) {
if (Array.isArray(json)) {
return json.map(v => create(h, v));
}
if (json !== null && typeof json === "object") {
return h(json.type, json.props, create(h, json.children));
}
return json;
}
const payload = ['h1', { id: 'hello' }, 'Hello worlds!']
const vdom = create(createElement, payload)
render(vdom, document.body);
</script>
</body>
</html>
'''
if __name__ == '__main__':
run(host='localhost', port=8089, reloader=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment