Ric*_*ick 2 python database django class
我正在使用Django,并希望能够在数据库中存储类,例如表单和模型,以便我可以通过用户界面轻松地创建它们,因为它们只是存储在数据库中而不是常规文件中.我真的不太了解这一点,我不确定这是否需要在python中使用exec或者是否有其他方式.我对此的搜索并没有发生太多变化.
基本上,它只是我进行数据库调用并获取类的内容,然后我想实例化它.对于如何最好地做这类事情,任何建议都表示赞赏.
编辑:为了回应__init__
类中恶意的想法,这些只是用于形式或模型之类的东西,通过验证类中的内容来严格控制,在类中永远不会有一个__init__
并且它基本上是不可能的因为我会验证服务器端的所有内容,在课堂上放置任何恶意内容.
不要将代码存储在数据库中!
Imagine a class with a malicious __init__
method finding it's way in your "class repository" in the database. This means whoever has write access to those database tables has the ability to read any file from your web server and even nuke it's file system, since they have the ability to execute any python code on it.