web2py how to import module at the same directory? -


i have file name default.py in controllers,and file getmsg.py @ same directory, can't import getmsg in default.py. why not? how import it?

the error:

traceback (most recent call last):   file "f:\xampp\htdocs\web2py\gluon\restricted.py", line 212, in restricted     exec ccode in environment   file "f:/xampp/htdocs/web2py/applications/tools/controllers/default.py", line 11, in <module>     import getmsg   file "f:\xampp\htdocs\web2py\gluon\custom_import.py", line 81, in custom_importer     raise importerror, 'cannot import module %s' % str(e) importerror: cannot import module 'getmsg' 

in web2py, controllers not python modules -- don't import them. can put modules in application's /modules folder , import there.

in theory, (assuming there __init__.py file in /controllers folder) can do:

import applications.myapp.controllers.getmsg 

but wouldn't considered standard practice. in particular, controllers not intended used regular python modules. executed in environment in of web2py api has been defined, if import controller module, code may make reference global objects not available, generate exceptions.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -