Build a Flaxon app with Jinax
This is a complete server-rendered starter. Jinax renders HTML on the server; Flaxon owns routing and APIs. Add a database and authentication before deploying user data.
1. Create the project
flaxon new store
cd store
python -m pip install "flaxon[standard,templates]"2. Add app.py
from datetime import datetime
from flaxon import Flaxon
from flaxon.jinax import Jinax
app = Flaxon("store", debug=True)
app.use_templates(Jinax("templates", auto_reload=True))
@app.get("/")
async def home(request):
products = [{"name": "Flaxon Mug", "price": 14.99}, {"name": "T-Shirt", "price": 29.99}]
return await request.render("home.html", {"title": "Flaxon Store", "products": products, "year": datetime.now().year})
@app.get("/api/products")
async def products():
return {"data": [{"name": "Flaxon Mug", "price": 14.99}]}
# Run with: flaxon run app:app --reload3. Add templates/home.html
<!doctype html>
<html><head><title>{{ title }}</title></head>
<body>
<h1>{{ title }}</h1>
{% for product in products %}
<article><h2>{{ product.name }}</h2><p>${{ product.price }}</p></article>
{% endfor %}
<small>{{ year }}</small>
</body></html>Run and deploy
flaxon run app:app --reload
curl http://127.0.0.1:8000/api/productsUse HTTPS, a production ASGI process, a persistent database, environment variables for secrets, CSRF protection for cookie-authenticated mutations, and authorization on every private route.
Next: use the mobile API and Play Store guide when a native client will consume the API.