python中将一个字符串转为类名,可以通过ORM方式进行数据库数据查询

版权声明:转载请标明出处 https://blog.csdn.net/gymaisyl/article/details/88228387
# 截取项目部分代码
@secdomain.route("/test")
def test():
    model = "Operate"
    if model in ["Operate", "Syslog", "StraLog"]:
        print("?")
        log = globals()[model].query.filter().all()
        print(log)
    return jsonify(status=1)

也就是说,可以通过

globals()["字符串"]

的方式,将字符串转为类名

猜你喜欢

转载自blog.csdn.net/gymaisyl/article/details/88228387