External web2py libraries

How can I import other external libraries into web2py? Is it possible to load libs into a static file? can anyone give me an example? thank

peter

+3
source share
2 answers

If the library comes with python, you can simply use the import in the same way as in a regular python script. You can put your import statements in your models, controllers and views, as well as your own python modules (stored in the modules folder). For example, I often use the trace module to register stack traces in my controllers:

import traceback

def myaction():
    try:
        ...
    except Exception as exc:
        logging.error(traceback.format_exc())
        return dict(error=str(exc))

python (, pyodbc), ( distutils easy_install pip), python web2py : python web2py.py. , . , , : python "import library_name". , .

python, , :

mymodule = local_import('module_name')

web2py , local_import, :

mymodule = local_import('module_name', reload=True)

. http://web2py.com/book/default/section/4/18?search=site-packages.

+5

web2py , , Python

import module_name

from module_name import object_name

, " "

0

Source: https://habr.com/ru/post/1747015/


All Articles