开发者

Django's Settings Magic

I'm building an application that borrows some design ideas from Django - the use of a per-project manage.py and settings.py, for example- and am trying to decip开发者_StackOverflow中文版her the magic.

When I want to refer to my Django settings, I generally import from django.settings. Obviously, though, my settings are in their own project-specific module. Any idea how this is accomplished?


An environment variable: DJANGO_SETTINGS_MODULE points to your settings module.

You can use the __import__ function: See http://docs.python.org/library/functions.html#import

And try, assuming your main app module is myapp:

myapp.settings = __import__(SETTINGS_MODULE_NAME, globals(), locals(), [], -1)

This is the dynamic equivalent of the from module import * statement

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜