Skip to content

Django: Async IO (ASGI vs WSGI)  #72

@hhstore

Description

@hhstore

写异步的 Django 代码 !!!


pip install -U channels



INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    ...
    'channels',
)


from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({
    # Empty for now (http->django views is added by default)
})


# asgi:

ASGI_APPLICATION = "myproject.routing.application"





  • channel 2: 新特性: https://channels.readthedocs.io/en/latest/one-to-two.html#full-async
    • full async (全异步)
    • Full Async
      Channels 2 is also built on a fundamental async foundation, and all servers are actually running an asynchronous event loop and only jumping to synchronous code when you interact with the Django view system or ORM. That means that you, too, can write fully asychronous code if you wish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions