Vue+Django+Channles实现websocket
Django端
django项目结构
-SevenDays
–SevenDays
–websocket
--auth.py
--console.py
1、SevenDays
settings.py
REDIS_OPTIONS = {
'HOST': '127.0.0.1',
'PORT': 6379,
'CHS_DB': 2,
'PASSWORD': ''
}
# django-channels配置
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": ["redis://:{}@{}:{}/{}".format(REDIS_OPTIONS['PASSWORD'], REDIS_OPTIONS['HOST'], REDIS_OPTIONS['PORT'], REDIS_OPTIONS['CHS_DB'])],
},
},
}
# 配置ASGI
ASGI_APPLICATION = "SevenDays.routing.application"
asgi.py
#-*-coding:utf-8-*-
import os
import django
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SevenDays.settings")
django.setup()
application