django_startup.py 542 Bytes
Newer Older
1 2 3 4
"""
Automatic execution of startup modules in Django apps.
"""

5 6 7
from importlib import import_module
from django.conf import settings

8

9 10 11 12 13
def autostartup():
    """
    Execute app.startup:run() for all installed django apps
    """
    for app in settings.INSTALLED_APPS:
14
        # See if there's a startup module in each app.
15
        try:
16
            mod = import_module(app + '.startup')
17 18
        except ImportError:
            continue
19 20 21 22

        # If the module has a run method, run it.
        if hasattr(mod, 'run'):
            mod.run()