10

i am using django channels in my project using using official django channels v2, my simple channels app is completed and working fine if run python manage.py runserver but i want to run django channels in different port so i am now using daphne
using daphne my_project.asgi:application --port 8001 it working fine in 8001 port

INFO     Starting server at tcp:port=8001:interface=127.0.0.1
INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)

and i also run python manage.py runserver in another terminal parallely working fine. now my both channels in 8001 and django in 8000 port working correctly but my runserver command running ASGI/Channels instead of wsgi development server,

Starting ASGI/Channels version 2.2.0 development server at http://127.0.0.1:8000/

instead of

Starting development server at http://127.0.0.1:8000/

settings.py

ASGI_APPLICATION = 'my_project.routing.application'

WSGI_APPLICATION = 'my_project.wsgi.application'

if i debug any function in views.py request, it is ASGI request instead of django wsgi request

asgi.py
import os
import django
from channels.routing import get_default_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
django.setup()
application = get_default_application()

my question is:

  1. how to get django request instead of ASGI request in our normal function view request(like def index(request)) or if we install django channels every request become ASGI request?
  2. what is the use of the python mange.py runworker command
karnataka
  • 425
  • 1
  • 4
  • 14

1 Answers1

3

Like you can read here: https://asgi.readthedocs.io/en/latest/

ASGI (Asynchronous Server Gateway Interface) is a spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications.

Where WSGI provided a standard for synchronous Python apps, ASGI provides one for both asynchronous and synchronous apps, with a WSGI backwards-compatibility implementation and multiple servers and application frameworks.

so answer for your question nr 1 is: Yes, all requests will be ASGI.

Question nr 2 - it's a command to run multiple workers to process your channel requests in asynchronous way https://channels.readthedocs.io/en/1.x/deploying.html#run-worker-servers

pawelbylina
  • 1,387
  • 10
  • 17
  • for question 1 if answer is yes then how third party apps will behave they were expecting django request right so from now onwards if i send the ASGI request(or instance) can they break?? – karnataka Sep 05 '19 at 10:01
  • or if yes then WSGI_APPLICATION is completely waste right? – karnataka Sep 05 '19 at 10:11
  • 1
    ASGI request has all attributes that normal django request has so this is not a problem, it should be transparent for you.`WSGI_APPLICATION` is necessary for `runserver` command https://stackoverflow.com/a/36107047/2156813 – pawelbylina Sep 05 '19 at 10:29
  • 1
    yes boss and even if i comment out the code WSGI_APPLICATION in settings file my application and runserver working fine – karnataka Sep 06 '19 at 04:40
  • @pako can you also see this my problem is also the similar one https://stackoverflow.com/questions/59527805/problem-in-running-asgi-environments-while-deploying-app-django-rest?noredirect=1 – Nabeel Ayub Dec 30 '19 at 09:48
  • Same question, quite green to Django. Installed channels, and now I can't seem to start my Django development server. runserver starts channels ASGI server, How can I run Django development server like it ran previously when I was not using channels? – Aditya Singh May 31 '21 at 07:53
  • @AdityaSingh provide more details. Why you cannot run development server? – pawelbylina Jun 04 '21 at 11:09
  • Thank you for your comment @pawelbylina, but I figured it out. There was an issue in my routing.py file. It's working fine now. – Aditya Singh Jun 07 '21 at 09:45