This is a work-in-progress!
It's highly recommended to install from source at the moment:
$ pip install git+https://github.com/zerointensity/view.py
from view.core.app import App
from view.dom.core import html_response
from view.dom.components import page
from view.dom.primitives import h1
app = App()
@app.get("/")
@html_response
async def home():
with page("Hello, view.py!"):
yield h1("Nobody expects the Spanish Inquisition")
app.run()from view.core.app import App
from view.dom.core import html_response
from view.dom.components import page
from view.dom.primitives import button, p
from view.dom.javascript import CompileContext, javascript_compiler
app = App()
@javascript_compiler
def click_button(ctx: CompileContext) -> None:
counter = ctx.document.get_element_by_id("counter")
number = ctx.parse_int(counter.inner_html)
number += 1
counter.inner_html = number
with ctx.condition(number == 42) as condition:
with condition.if_true():
ctx.window.alert("The answer!")
with condition.if_false():
ctx.console.log(number)
@app.get("/")
@html_response
async def home():
with page("Counter"):
yield p("0", id="counter")
yield button("Click me!", onclick=click_button)
app.run()view.py is distributed under the terms of the MIT license.