flask_admin.tools¶
- import_module(name: str, required: bool = True) ModuleType | None[source]¶
Import module by name
- Parameters:
name – Module name
required – If set to True and module was not found - will throw exception. If set to False and module was not found - will return None. Default is True.
- import_attribute(name: str) Any[source]¶
Import attribute using string reference.
- Parameters:
name – String reference.
Raises ImportError or AttributeError if module or attribute do not exist.
Example:
import_attribute('a.b.c.foo')
- module_not_found(additional_depth: int = 0) bool[source]¶
Checks if ImportError was raised because module does not exist or something inside it raised ImportError
- Parameters:
additional_depth – supply int of depth of your call if you’re not doing import on the same level of code - f.e., if you call function, which is doing import, you should pass 1 for single additional level of depth