how to dynamically create an instance of a class in python?

Assuming you have already imported the relevant classes using something like

from [app].models import *

all you will need to do is

klass = globals()["class_name"]
instance = klass()

Leave a Comment