33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
"""
|
|
WSGI config for daren_project project.
|
|
|
|
It exposes the WSGI callable as a module-level variable named ``application``.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
|
"""
|
|
|
|
import os
|
|
import django
|
|
|
|
# 首先设置 Django 设置模块
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'daren_project.settings')
|
|
django.setup() # 添加这行来初始化 Django
|
|
|
|
# 然后再导入其他模块
|
|
from django.core.asgi import get_asgi_application
|
|
from channels.routing import ProtocolTypeRouter, URLRouter
|
|
from channels.auth import AuthMiddlewareStack
|
|
from channels.security.websocket import AllowedHostsOriginValidator
|
|
from apps.chat.routing import websocket_urlpatterns
|
|
from apps.common.middlewares import TokenAuthMiddleware
|
|
|
|
# 使用TokenAuthMiddleware代替AuthMiddlewareStack
|
|
application = ProtocolTypeRouter({
|
|
"http": get_asgi_application(),
|
|
"websocket": AllowedHostsOriginValidator(
|
|
TokenAuthMiddleware(
|
|
URLRouter(websocket_urlpatterns)
|
|
)
|
|
),
|
|
}) |