Running startup code right after Django settings? (also for commands)

别等时光非礼了梦想. 提交于 2019-11-28 13:36:09

The normal place for startup-like code is in a urls.py (when you need the settings to be already loaded). Django doesn't have a good spot yet for this.

(There is an "app refactor" branch that a gsoc student worked on in 2011, but it didn't get merged into core django yet. This "app refactor" includes a solution to your very problem, but that doesn't help you...)

You mention that a management command also needs it. Is that your own management command? Nothing stops you from importing the urls.py there, is it?

This is sadly one of the few Django weak points. Luckily there aren't that many :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!