mirror of
https://github.com/django/daphne.git
synced 2025-07-13 09:22:17 +03:00
Made daphne installable as a Django app.
Added system check to ensure daphne is installed before django.contrib.staticfiles.
This commit is contained in:
parent
438b7ad06d
commit
43237a4258
20
daphne/apps.py
Normal file
20
daphne/apps.py
Normal file
|
@ -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)
|
20
daphne/checks.py
Normal file
20
daphne/checks.py
Normal file
|
@ -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",
|
||||
)
|
||||
]
|
Loading…
Reference in New Issue
Block a user