T() in modules

57 views
Skip to first unread message

黄祥

unread,
Jun 18, 2019, 6:39:21 AM6/18/19
to web2py-users
web2py™ Version 2.18.5-stable
tryin to use T() in modules
Traceback (most recent call last):
 
File "/Users/sugizo/learn/python/web2py/gluon/restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "/Users/sugizo/learn/python/web2py/applications/test/controllers/api.py", line 4, in <module>
   
import test_db
 
File "/Users/sugizo/learn/python/web2py/gluon/custom_import.py", line 74, in custom_importer
    modules_prefix
, globals, locals, (itemname,), level)
 
File "/Users/sugizo/learn/python/web2py/applications/test/modules/test_db.py", line 59, in <module>
    format
= lambda r: \
 
File "/Users/sugizo/learn/python/web2py/gluon/packages/dal/pydal/base.py", line 592, in define_table
    table
= self.lazy_define_table(tablename, *fields, **kwargs)
 
File "/Users/sugizo/learn/python/web2py/gluon/packages/dal/pydal/base.py", line 633, in lazy_define_table
    on_define
(table)
 
File "/Users/sugizo/learn/python/web2py/applications/test/modules/test_db.py", line 36, in on_define_address
    table
.zip_code.requires = IS_EMPTY_OR(IS_MATCH('^\d{5,5}$', error_message = T('not a Zip Code') ) )
NameError: name 'T' is not defined

tryin to import languages but still got an error
from gluon.languages import *

Traceback (most recent call last):
 
File "/Users/sugizo/learn/python/web2py/gluon/restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "/Users/sugizo/learn/python/web2py/applications/test/controllers/api.py", line 4, in <module>
   
import test_db
 
File "/Users/sugizo/learn/python/web2py/gluon/custom_import.py", line 74, in custom_importer
    modules_prefix
, globals, locals, (itemname,), level)
 
File "/Users/sugizo/learn/python/web2py/applications/test/modules/test_db.py", line 7, in <module>
   
from gluon.languages import *
AttributeError: module 'gluon.languages' has no attribute 'translator'

any hints ?

thx n best regards,
stifan

Anthony

unread,
Jun 18, 2019, 10:24:38 AM6/18/19
to web2py-users

黄祥

unread,
Jun 18, 2019, 12:51:32 PM6/18/19
to web2py-users
forgot about that one, thx Anthony, think the same code can work in web2py n web3py just set the correct imported modules <path>, seems the web2py have a hidden features that store in current module

Massimo Di Pierro

unread,
Jun 24, 2019, 2:53:25 AM6/24/19
to web2py-users
We do not want current in Web3py. We do not need it because T is a fixture that takes care of its own thread safety
Reply all
Reply to author
Forward
0 new messages