2020-03-24 22:40:14 +03:00
|
|
|
"""
|
|
|
|
ASGI config for {{ cookiecutter.project_name }} project.
|
|
|
|
|
|
|
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/dev/howto/deployment/asgi/
|
2020-04-07 07:23:31 +03:00
|
|
|
|
2020-03-24 22:40:14 +03:00
|
|
|
"""
|
2020-04-16 11:11:15 +03:00
|
|
|
import os
|
2020-03-24 22:40:14 +03:00
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from django.core.asgi import get_asgi_application
|
2020-03-25 04:42:28 +03:00
|
|
|
|
2020-03-24 22:40:14 +03:00
|
|
|
# This allows easy placement of apps within the interior
|
|
|
|
# {{ cookiecutter.project_slug }} directory.
|
2020-04-30 01:07:21 +03:00
|
|
|
ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent
|
|
|
|
sys.path.append(str(ROOT_DIR / "{{ cookiecutter.project_slug }}"))
|
2020-04-13 17:57:42 +03:00
|
|
|
|
2020-04-16 11:11:15 +03:00
|
|
|
# If DJANGO_SETTINGS_MODULE is unset, default to the local settings
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
|
|
|
|
2020-04-13 17:57:42 +03:00
|
|
|
# This application object is used by any ASGI server configured to use this file.
|
2020-03-24 22:40:14 +03:00
|
|
|
django_application = get_asgi_application()
|
|
|
|
# Apply ASGI middleware here.
|
|
|
|
# from helloworld.asgi import HelloWorldApplication
|
|
|
|
# application = HelloWorldApplication(application)
|
|
|
|
|
2020-04-07 07:23:31 +03:00
|
|
|
# Import websocket application here, so apps from django_application are loaded first
|
2020-04-13 17:57:42 +03:00
|
|
|
from config.websocket import websocket_application # noqa isort:skip
|
2020-03-28 04:32:17 +03:00
|
|
|
|
2020-03-24 22:40:14 +03:00
|
|
|
|
|
|
|
async def application(scope, receive, send):
|
2020-03-24 23:12:47 +03:00
|
|
|
if scope["type"] == "http":
|
2020-03-24 22:40:14 +03:00
|
|
|
await django_application(scope, receive, send)
|
2020-03-24 23:12:47 +03:00
|
|
|
elif scope["type"] == "websocket":
|
2020-03-24 22:40:14 +03:00
|
|
|
await websocket_application(scope, receive, send)
|
|
|
|
else:
|
|
|
|
raise NotImplementedError(f"Unknown scope type {scope['type']}")
|