datadvance / DjangoChannelsGraphqlWs

Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
MIT License
281 stars 84 forks source link

using asgi server such as daphne error #99

Open kimutaiRop opened 1 year ago

kimutaiRop commented 1 year ago

I have been tryign to use asgi server to run websocket in production and kept gettign error. wen though the example and that is when I realized that this could be issue with the way the asgi application is set, Is it all right the way schema is loaded before the django application is mounted?

tried this daphne example:application -b 0.0.0.0 -p 8000 command in example directory and it is falling. Django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I dont know coz I dont see such issue maybe someone know how I can run production asgi server or that just people using django runserver in production

kimutaiRop commented 1 year ago

ok just weird posted this and instatly was able to solve this by adding

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
import django
django.setup()

ontop of the all example.py file as same applied to my server but I think it is a good idea to include such in the example file for easy reference