Sorry for the late reply. I come back to you with some news : i understand i need to use a daphne server for secure websockets.
I can’t use secure websockets on Django with the sll enabled. I use the sslserver package for Django to allow HTTPS on the development server. My goal is to make a secure chat.
Here is the configuration :
INSTALLED_APPS = [
'channels',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sslserver',
'accounts',
'chat',
]
#WSGI_APPLICATION = 'sendapp.wsgi.application'
ASGI_APPLICATION = 'sendapp.asgi.application'
# LEARN CHANNELS
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer"
},
}
Concerning the asgi file :
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sendapp.settings')
application = ProtocolTypeRouter({
'https': get_asgi_application(),
'websocket': AuthMiddlewareStack(URLRouter(ws_urlpatterns))
})
I start the Django server this way :
python .\manage.py runsslserver --certificate .\sendapp\certif.crt --key .\sendapp\code.key 0.0.0.0:8000
I understand that to use secure websockets, you have to use a Daphne server. So I tried to run it in its basic configuration in the root of manage.py :
daphne sendapp.asgi:application
but i have this error code in the shell :
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.