1. Your first page¶
Create guestbook.py:
guestbook.py¶
"""Tutorial step 1: an app with one page."""
from rational import App, Container, Heading, Page, Text
app = App(title="Guestbook")
@app.page("/")
class Home(Page):
title = "Guestbook"
def render(self):
return Container(
Heading("Guestbook", level=1),
Text("Leave a message for the next visitor."),
max_width=640,
)
if __name__ == "__main__":
app.run()
Run it in development mode:
$ python guestbook.py --dev
Open http://127.0.0.1:8000. Leave the server running: from now on, every time you save the file, the server restarts and the browser reloads by itself.
What happened¶
AppThe application. It is an ASGI app built on FastAPI, so any ASGI server can run it.
@app.page("/")Registers a
Pageat a URL. One page instance exists per page view.render()Returns what to show.
Container,HeadingandTextare primitives: functions that build HTML elements with good default styles.app.run()Reads the command line:
--devfor development,--prodfor production.
Look at the page source in your browser. It is plain HTML and CSS. Because this page has no event handlers, Rational doesn’t send any JavaScript at all.
Next: 2. Components and props.