diff --git a/daphne/apps.py b/daphne/apps.py new file mode 100644 index 0000000..3dd62fa --- /dev/null +++ b/daphne/apps.py @@ -0,0 +1,20 @@ +# Import the server here to ensure the reactor is installed very early on in case other +# packages import twisted.internet.reactor (e.g. raven does this). +import daphne.server # noqa: F401 + + +try: + # Allow that Django is not installed. + from django.apps import AppConfig + from django.core import checks + from .checks import check_daphne_installed +except ImportError: + pass +else: + + class DaphneConfig(AppConfig): + name = "daphne" + verbose_name = "Daphne" + + def ready(self): + checks.register(check_daphne_installed, checks.Tags.staticfiles) diff --git a/daphne/checks.py b/daphne/checks.py new file mode 100644 index 0000000..ba67d12 --- /dev/null +++ b/daphne/checks.py @@ -0,0 +1,20 @@ +# Django system check to ensure daphne app is listed in INSTALLED_APPS before django.contrib.staticfiles. +from django.core.checks import Error, register + + +@register() +def check_daphne_installed(app_configs, **kwargs): + from daphne.apps import DaphneConfig + from django.apps import apps + from django.contrib.staticfiles.apps import StaticFilesConfig + + for app in apps.get_app_configs(): + if isinstance(app, DaphneConfig): + return [] + if isinstance(app, StaticFilesConfig): + return [ + Error( + "Daphne must be listed before django.contrib.staticfiles in INSTALLED_APPS.", + id="daphne.E001", + ) + ]