learn-py4web.github.io

Unit 8: Creating database tables, and using forms to insert/edit/view/delete data

In this unit, we learn how we can create simple database tables, and how we can use py4web and its forms to insert, view, edit, and delete data from the database.

Resources

Code

Videos

Note

Compared to the recorded lecture, the code for form processing with py4web changed in one important respect. The rule is this. Suppose we create a URL signer url_signer. Then:

Whenever `url_signer` is used in a template, we must include `url_signer` in the `@action.uses`. 

Example:

@action('index')
@action.uses('index.html', url_signer, db, auth.user)
def index():
    ...

This makes sense, as the fixtures are the things that should be “in place” before the page is processed. More in detail, url_signer, to sign the URL, needs a key that is in the session. In the on_request method, the URL signer generates the key it needs to sign the URLs. Hence, we must list the url_signer in the fixtures, to ensure that the signing key has been produced before the template is processed.