How to access a python module variable using a string [ django ]
问题 I have a django application, with a module called "app" Now this module has a file called "urls.py" which has a variable called "HOME_URL " What I'm trying to do ? app_label = "app" url = __import__(app_label).urls.HOME_URL print url That obviously doesn't work, but I hope you got what I'm trying to do, If not please comment I will edit the question to contain more info. 回答1: You can use import_module to load a module relative to the root of a django project. from django.utils.importlib