这里使用django 3.1.5
二、django项目
安装模块
pip3 install django-cors-headers channels
新建项目websocket_demo
?...INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes...',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware...('admin/', admin.site.urls),
]
websocket_urlpatterns = [
# 前端请求websocket连接
path('wx/', ChatConsumer.as_asgi