Where should I put global application setup routines in Django?
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.
精彩评论