Skip to content
Projects

About

The Batteries-Detachable Web Framework

Web & Apps

How these counts are measured

Measured star growth

in 24h
0
in 7 days
0
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original
view.py logo

The Batteries-Detachable Web Framework

This is a work-in-progress!

Installation

It's highly recommended to install from source at the moment:

$ pip install git+https://github.com/zerointensity/view.py

Examples

Simple Hello World

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()

Button Counter

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()

Copyright

view.py is distributed under the terms of the MIT license.

Explore related projects

Loading…