examples/update_form.py
import os
from py4web import action
from py4web.utils.form import Form, FormStyleDefault
from .common import T, db, session
# exposed as /examples/create_form or /examples/update_form/<id>
@action("update_form/<id>", method=["GET", "POST"])
@action.uses("examples/form.html", db, session, T)
def update_form(id):
form = Form(db.person, id, deletable=False, 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>