Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django application onload?

Tags:

django

Is there a way to hook on the loading of the django application? I want to be able to execute code when the application is loaded, so that I can for example create static variables to be used later on by the application or establish connections to other servers.

The best I came across was to add code in the __init__.py file (How do I create application scope variable django?) but the problem with this solution is that I want my code to be executed after django has finished its startup process, and not in the middle/start of it.

Another solution I came up with is to have a view that handles this process and then when the application is deployed I issue a request to the url of the view. I don't like this solution very much, I prefer it to be a part of the loading of the application.

Any ideas of how to pull this out? Thanks;

edit: Apllication refers to the entire django project and not one of the INSTALLED_APPS

like image 223
Nitzan Tomer Avatar asked Mar 19 '26 18:03

Nitzan Tomer


1 Answers

Right now, there's really no good way to do this as Django doesn't have a startup signal. Interestingly, there is a ticket for this, but it's strangely tied to a branch that is being held up by another ticket. I'm not sure if Django 1.4 is feature-locked, yet, but as it's in release candidate stage, my bet is that it is. So, maybe you might get this in Django 1.5 whenever that happens.

like image 176
Chris Pratt Avatar answered Mar 21 '26 09:03

Chris Pratt