开发者

Where should I put global application setup routines in Django?

开发者 https://www.devze.com 2023-03-24 15:14 出处:网络
In a large Django project, I have several evil monkey-patching hacks to execute at application startup time. However, I don\'t quite see a correct place for such hackery: neither url开发者_C百科s.py n

In a large Django project, I have several evil monkey-patching hacks to execute at application startup time. However, I don't quite see a correct place for such hackery: neither url开发者_C百科s.py nor settings.py nor manage.py seem fit for this. Where would you recommend I put those?


In python you will always come across initialization. That's why its always better to use init for initialization. Even in django when you create a project it must have an init.py in it. I usually put all my initialization in __init__.py its a safe and clean way. You can do the same rather than create another initialization module.


There isn't really a good answer to this question at the moment. There's a Summer of Code project at the moment to rewrite the app loading process, which hopefully will include hooks for initialization code.

In the meantime, I think the best place for this is in urls.py. The admin application and Haystack both do it there, and it seems a good pattern.

0

精彩评论

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

关注公众号