首页
仓库
文档
nginx手册
Docker手册
workerman
Flask
PHP
python
RabbitMQ
其他
Linux
占位1
占位2
目录
fun.py ```python #自定义函数 def haha(s): return s+'haha!' #获取自定义函数列表 def get_custom_functions(): import inspect # 获取当前模块的名字 current_module_name = sys.modules[__name__].__name__ # 获取当前模块 current_module = sys.modules[current_module_name] """获取模块中的自定义函数列表""" custom_functions = [] for name, obj in inspect.getmembers(current_module): if inspect.isfunction(obj) and getattr(obj, '__module__', None) == current_module.__name__: custom_functions.append(name) return custom_functions ``` app.py ```python from flask import Flask import fun 创建app略... custom_functions_list = fun.get_custom_functions() for v in custom_functions_list: app.add_template_filter(getattr(fun, v), v) # 注册模板过滤器 app.add_template_global(getattr(fun, v), v) # 注册模板全局函数 ```