Lipton
Lipton

Reputation: 49

web2py: global name 'crud' is not defined

I am currently following a web2py tutorial and I am asked to append to my controls/default.py:

def entry_post():
"""returns a form where the can entry a post"""
form = crud.create(db.post)
return dict(form=form)

Which is fine but if I try to go to: mywebsite/app/default/entry_post I get a ticket error: global name 'crud' is not defined

Now, I've read the web2py documentation and I know that crud.create(db.table) is a valid syntax, so why does this happen?

Thanks for your answer

Upvotes: 1

Views: 1529

Answers (2)

Massimo
Massimo

Reputation: 1653

BTW. Crud is an old API which we no longer support.

form = crud.create(db.post)

should be rewritten as

form = SQLFORM(db.post).process()

Upvotes: 4

Anthony
Anthony

Reputation: 25536

Crud must be imported and instantiated:

from gluon.tools import Crud
crud = Crud(db)

This is often done in a model file so it will be available in any controller.

Upvotes: 0

Related Questions