hi
i'm having some trouble with web2py models:

# -*- coding: utf-8 -*-
db = DAL("sqlite://storage.sqlite")
from gluon.tools import Crud
crud = Crud(db)


db.define_table("shout",
          Field("author", "string"),
          Field("shout","text"))
   

          
          
          
          
          
db.shout.shout.requires = IS_NOT_EMPTY

(there is more but it is for the admin interface)

It is all correct but I get this error:

Traceback (most recent call last):
  File "/Users/SamarthAgarwal/Dropbox/web2py/gluon/restricted.py", line 194, in restricted
    exec ccode in environment
  File "/Users/SamarthAgarwal/Dropbox/web2py/applications/shoutout_/controllers/default.py", line 74, in <module>
  File "/Users/SamarthAgarwal/Dropbox/web2py/gluon/globals.py", line 149, in <lambda>
    self._caller = lambda f: f()
  File "/Users/SamarthAgarwal/Dropbox/web2py/applications/shoutout_/controllers/default.py", line 13, in index
    form = crud.create(db.shout,
  File "/Users/SamarthAgarwal/Dropbox/web2py/gluon/dal.py", line 4511, in __getattr__
    return self[key]
  File "/Users/SamarthAgarwal/Dropbox/web2py/gluon/dal.py", line 4505, in __getitem__
    return dict.__getitem__(self, str(key))
KeyError: 'shout'

My code;

# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations

#########################################################################
## This is a samples controller
## - index is the default action of any application
## - user is required for authentication and authorization
## - download is for downloading files uploaded in the db (does streaming)
## - call exposes all registered services (none by default)
#########################################################################

def index():
    form = crud.create(db.shout,
                       message='Your shout has been posted!!', next=URL())
    shouts = db(db.shout).select()
    return dict(shouts=shouts, form=form)
    
    
    
    
 
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """
    return dict(form=auth())


def download():
    """
    allows downloading of uploaded files
    http://..../[app]/default/download/[filename]
    """
    return response.download(request,db)


def call():
    """
    exposes services. for example:
    http://..../[app]/default/call/jsonrpc
    decorate with @services.jsonrpc the functions to expose
    supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
    """
    return service()


@auth.requires_signature()
def data():
    """
    http://..../[app]/default/data/tables
    http://..../[app]/default/data/create/[table]
    http://..../[app]/default/data/read/[table]/[id]
    http://..../[app]/default/data/update/[table]/[id]
    http://..../[app]/default/data/delete/[table]/[id]
    http://..../[app]/default/data/select/[table]
    http://..../[app]/default/data/search/[table]
    but URLs bust be signed, i.e. linked with
      A('table',_href=URL('data/tables',user_signature=True))
    or with the signed load operator
      LOAD('default','data.load',args='tables',ajax=True,user_signature=True)
    """
    return dict(form=crud())

response._vars=response._caller(index)

HELP!

I fixed it there were to instances of db the second one deleting the first

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.