2
Put your startup code in a separate file, for example startup.py
and then alter these two files:
manage.py
# some code
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "[project name].settings")
if __name__ == "__main__":
import startup
# the rest of the code
[project name]/wsgi.py
# some code
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "[project name].settings")
import startup
# the rest of the code
Note the order: import is always after environ
setting (might not be important, depends on what startup does).
In Django1.7 you can use ready
function per application. Read this:
https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.ready
Source:stackexchange.com