Back to Examples Run this application locally to try examples

examples/create_form.py

import os

from py4web import action
from py4web.utils.form import Form, FormStyleDefault

from .common import T, session
from .models import db


# exposed as /examples/create_form or /examples/update_form/<id>
@action("create_form", method=["GET", "POST"])
@action.uses("examples/form.html", db, session, T)
def create_form():
    form = Form(db.person, formstyle=FormStyleDefault)
    rows = db(db.person).select()
    return dict(form=form, rows=rows)

templates/examples/form.html

[[extend 'layout.html']]

<h2 class="title">Form Superhero Identity</h2>

[[=form]]

<h2 class="title">Rows</h2>

<ul>
  [[for row in rows:]]
  <li>[[=row.id]]: [[=row.name]] ([[=row.job]]) <a href="../update_form/[[=row.id]]">edit</a></li>
  [[pass]]
  <li><a href="../create_form">create</a></li>
</ul>