TypeError: object of type 'Field' has no len()

19 views
Skip to first unread message

黄祥

unread,
Jun 18, 2019, 12:47:30 PM6/18/19
to web2py-users
controllers/api.py
import table_test
def test():
   
return table_test.test

modules/table_test.py
from gluon.dal import *
from gluon.validators import *
from gluon import current
import field_constructor
db
= DAL('sqlite://test.sqlite', pool_size = 1)
def on_define_test(table):
    T
= current.T
    table
.test.label = T('Test')
    table
.test.requires = IS_NOT_EMPTY()
    table
.test.widget = field_constructor.widget_string
test
= db.define_table('test',
   
Field('test'),
    on_define
= on_define_test)

modules/field_constructor.py
from gluon import *
widget_string
= lambda field, value: \
    SQLFORM
.widgets.string.widget(field, value,
                                  _class
= "form-control string",
                                  _placeholder
= current.T('Should be filled') )

ERROR:Rocket.Errors.Thread-6:Traceback (most recent call last):
 
File "/Users/sugizo/learn/python/web2py/gluon/rocket.py", line 1288, in run
   
self.run_app(conn)
 
File "/Users/sugizo/learn/python/web2py/gluon/rocket.py", line 1802, in run_app
   
self.write(data, sections)
 
File "/Users/sugizo/learn/python/web2py/gluon/rocket.py", line 1722, in write
   
self.conn.sendall(b'%x\r\n%s\r\n' % (len(data), to_bytes(data, 'ISO-8859-1')))
TypeError: object of type 'Field' has no len()

error only appears in terminal :
python ~/learn/python/web2py/web2py.py --nogui --no-banner -a a -i 0.0.0.0 -p 8000

any hints ?

thx n best regards,
stifan
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages