See 
http://web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules.
 
You can use current.T.

Anthony

On Tuesday, June 18, 2019 at 6:39:21 AM UTC-4, 黄祥 wrote:
>
> 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
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/159718bc-96f8-4d8c-8348-f7696b163e77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to