开发者

web2py TypeError: id() takes exactly one argument (0 given)

I am making a web service in Web2Py which accept some parameters and inserts them into a table. I am getting the following error while I am inserting data in this 1 table

 Traceback (most recent call last):
  File "E:\Development\Python\web2py\gluon\restricted.py", line 192, in restricted
    exec ccode in environment
  File "E:/Development/Python/web2py/applications/my_app/controllers/mobi.py", line 96, in <module>
  File "E:\Development\Python\web2py\gluon\globals.py", line 145, in <lambda>
    self._caller = lambda f: f()
  File "E:/Development/Python/web2py/applications/my_app/controllers/mobi.py", line 81, in createwish
    wish_id = db.t_wish.insert(f_user_id = id, f_category_id = category_id, f_sub_category_id = sub_category_id, f_min_price = min_price, f_max_price = max_price, f_location_range = location_range, f_keywords = keywords)
  File "E:\Development\Python\web2py\gluon\dal.py", line 4786, in insert
    return self._db._adapter.insert(self,self._listify(fields))
  File "E:\Development\Python\web2py\gluon\dal.py", line 838, in insert
    query = self._insert(table,fields)
  File "E:\Development\Python\web2py\gluon\dal.py", line 834, in _insert
    values = ','.join(self.expand(v,f.type) for f,v in fields)
  File "E:\Development\Python\web2py\gluon\dal.py", line 834, in <genexpr>
    values = ','.join(self.expand(v,f.type) for f,v in fields)
  File "E:\Development\Python\web2py\gluon\dal.py", line 951, in expand
    return self.represent(expression,field_type)
  File "E:\Development\Python\web2py\gluon\dal.py", line 1266, in represent
    obj = obj()
TypeError: id() takes exactly one argument (0 given)

The model is this

########################################
db.define_table('t_wish',
    Field('id','id',
          represent=lambda id:SPAN(id,' ',A('view',_href=URL('wish_read',args=id)))),
    Field('f_user_id', type='string',
          label=T('User Id')),
    Field('f_category_id', type='string',
          label=T('Category Id')),
    Field('f_sub_category_id', type='string',
          label=T('Sub Category Id')),
    Field('f_min_price', type='integer',
          label=T('Min Price')),
    Field('f_max_price', type='integer',
          label=T('Max Price')),
    Field('f_location_range', type='integer',
          label=T('Location Range')),
    Field('f_keywords', type='string',
          label=T('Keywords')),
    Field('is_active','boolean',default=True,
          label=T('Active'),writable=False,readable=False),
    Field('created_on','datetime',default=request.now,
          label=T('Created On'),writable=False,readable=False),
    Field('modified_on','datetime',default=request.now,
          label=T('Modified On'),writable=False,readable=False,
  开发者_如何学C        update=request.now),
    Field('created_by',db.auth_user,default=auth.user_id,
          label=T('Created By'),writable=False,readable=False),
    Field('modified_by',db.auth_user,default=auth.user_id,
          label=T('Modified By'),writable=False,readable=False,
          update=auth.user_id),
    format='%(f_user_id)s',
    migrate=settings.migrate)

db.define_table('t_wish_archive',db.t_wish,Field('current_record','reference t_wish'))

Code to insert the data is this

#Creating a wish
def createwish():
    try:
        user_id = request.vars['id']
        category_id = request.vars['category_id']
        sub_category_id = request.vars['sub_category_id']
        min_price = request.vars['min_price']
        max_price = request.vars['max_price']
        location_range = request.vars['loc_range']
        keywords = request.vars['keywords']
    except:
        raise HTTP(400, 'BAD REQUEST: Requires all params - id, category_id, sub_category_id, min_price, max_price, loc_range, keywords')

   # try:    
    wish_id = db.t_wish.insert(f_user_id = id, f_category_id = category_id, f_sub_category_id = sub_category_id, f_min_price = min_price, f_max_price = max_price, f_location_range = location_range, f_keywords = keywords)

    return sj.dumps({'result':'success', 'wish_id':wish_id})
    #except:
     #   raise HTTP(500, 'Internal Server Error')  

Any ideas?


You have problems here:

db.define_table('t_wish',
    Field('id','id',
          represent=lambda id:SPAN(id,' ',A('view',_href=URL('wish_read',args=id)))),

and here:

# try:    
    wish_id = db.t_wish.insert(f_user_id = id, ...)

change to:

db.define_table('t_wish',
    Field('id','id',
          represent=lambda value:SPAN(value,' ',A('view',_href=URL('wish_read',args=id)))),

and

# try:    
    wish_id = db.t_wish.insert(f_user_id = user_id, ....)

You cannot use 'id' because it is a Python built in


File "E:/Development/Python/web2py/applications/my_app/controllers/mobi.py", line 81, in createwish
    wish_id = db.t_wish.insert(f_user_id = id, f_category_id = category_id, f_sub_category_id = sub_category_id, f_min_price = min_price, f_max_price = max_price, f_location_range = location_range, f_keywords = keywords)

Note the f_user_id = id, that's the python builtin. I'm assuming you mean some other variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜