Hello

The smallest Rational Web app: one themed, server-rendered page.

examples/hello/app.py
"""The smallest Rational Web app: one static, themed page (no JavaScript is shipped).

Run:  python examples/hello/app.py --dev    # hot reload, readable errors
      python examples/hello/app.py --prod   # production server
then open http://127.0.0.1:8000
"""

from rational import App, Card, Container, Heading, Page, Text

app = App(title="Hello")


@app.page("/")
class Hello(Page):
    def render(self):
        return Container(
            Card(
                Heading("Hello, Rational Web", level=1),
                Text("This page is plain server-rendered HTML with compiled, themed CSS.", muted=True),
            ),
            tag="main",
            max_width=640,
        )


if __name__ == "__main__":
    app.run()

Things to notice:

  • There are no event handlers, so the page ships no JavaScript: open the page source and look for <script>, there is none.

  • Container(..., tag="main") gives the page a <main> landmark for assistive technology.

  • app.run() makes python app.py --dev and python app.py --prod work.

Run it:

$ python examples/hello/app.py --dev