Django 5.1 Documentation
define asynchronous (async def) method handlers to leverage asynchronous code using await: import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async **kwargs): # Perform io-blocking view logic using await, sleep for example. await asyncio.sleep(1) return HttpResponse("Hello async world!") Within a single view-class, all user-defined same signature but declared using async def: async def my_callback(sender, **kwargs): await asyncio.sleep(5) print("Request finished!") Signals can be sent either synchronously or asynchronously0 码力 | 3513 页 | 3.17 MB | 1 年前3Django 5.1.2 Documentation
define asynchronous (async def) method handlers to leverage asynchronous code using await: import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async **kwargs): # Perform io-blocking view logic using await, sleep for example. await asyncio.sleep(1) return HttpResponse("Hello async world!") Within a single view-class, all user-defined same signature but declared using async def: async def my_callback(sender, **kwargs): await asyncio.sleep(5) print("Request finished!") Signals can be sent either synchronously or asynchronously0 码力 | 3519 页 | 3.17 MB | 1 年前3Django 5.0.x Documentation
define asynchronous (async def) method handlers to leverage asynchronous code using await: import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async **kwargs): # Perform io-blocking view logic using await, sleep for example. await asyncio.sleep(1) return HttpResponse("Hello async world!") Within a single view-class, all user-defined same signature but declared using async def: async def my_callback(sender, **kwargs): await asyncio.sleep(5) print("Request finished!") Signals can be sent either synchronously or asynchronously0 码力 | 3407 页 | 3.21 MB | 1 年前3Django 4.1.x Documentation
async requests by checking if the get_response object you are passed is a coroutine function, using asyncio.iscoroutinefunction. The django.utils.decorators module contains sync_only_middleware(), async_only_middleware() performance penalty. Here’s an example of how to create a middleware function that supports both: import asyncio from django.utils.decorators import sync_and_async_middleware @sync_and_async_middleware def si simple_middleware(get_response): # One-time configuration and initialization goes here. if asyncio.iscoroutinefunction(get_response): async def middleware(request): # Do something0 码力 | 3240 页 | 3.13 MB | 1 年前3Django 5.1.2 Documentation
define asynchronous (async def) method handlers to leverage asynchronous code using await: import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async request, *args, **kwargs): # Perform io-blocking view logic using await, sleep for example. await asyncio.sleep(1) return HttpResponse("Hello async world!") Within a single view-class, all user-defined the same signature but declared using async def: async def my_callback(sender, **kwargs): await asyncio.sleep(5) print("Request finished!") Signals can be sent either synchronously or asynchronously0 码力 | 2923 页 | 9.62 MB | 1 年前3Django 5.1 Documentation
define asynchronous (async def) method handlers to leverage asynchronous code using await: import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async request, *args, **kwargs): # Perform io-blocking view logic using await, sleep for example. await asyncio.sleep(1) return HttpResponse("Hello async world!") Within a single view-class, all user-defined the same signature but declared using async def: async def my_callback(sender, **kwargs): await asyncio.sleep(5) print("Request finished!") Signals can be sent either synchronously or asynchronously0 码力 | 2917 页 | 9.59 MB | 1 年前3Django 5.0.x Documentation
define asynchronous (async def) method handlers to leverage asynchronous code using await: import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async request, *args, **kwargs): # Perform io-blocking view logic using await, sleep for example. await asyncio.sleep(1) return HttpResponse("Hello async world!") Within a single view-class, all user-defined the same signature but declared using async def: async def my_callback(sender, **kwargs): await asyncio.sleep(5) print("Request finished!") Signals can be sent either synchronously or asynchronously0 码力 | 2878 页 | 9.60 MB | 1 年前3Django 4.1.x Documentation
async requests by checking if the get_response object you are passed is a coroutine function, using asyncio. iscoroutinefunction. The django.utils.decorators module contains sync_only_middleware(), async_only_middleware() performance penalty. Here’s an example of how to create a middleware function that supports both: import asyncio from django.utils.decorators import sync_and_async_middleware @sync_and_async_middleware def simple_middleware(get_response): # One-time configuration and initialization goes here. if asyncio.iscoroutinefunction(get_response): async def middleware(request): # Do something here! response =0 码力 | 2777 页 | 9.32 MB | 1 年前3Django 4.0.x Documentation
async requests by checking if the get_response object you are passed is a coroutine function, using asyncio.iscoroutinefunction. The django.utils.decorators module contains sync_only_middleware(), async_only_middleware() performance penalty. Here’s an example of how to create a middleware function that supports both: import asyncio from django.utils.decorators import sync_and_async_middleware @sync_and_async_middleware def si simple_middleware(get_response): # One-time configuration and initialization goes here. if asyncio.iscoroutinefunction(get_response): async def middleware(request): # Do something here! response = await0 码力 | 2248 页 | 7.90 MB | 1 年前3Django 4.0.x Documentation
async requests by checking if the get_response object you are passed is a coroutine function, using asyncio.iscoroutinefunction. The django.utils.decorators module contains sync_only_middleware(), async_only_middleware() performance penalty. Here’s an example of how to create a middleware function that supports both: import asyncio from django.utils.decorators import sync_and_async_middleware @sync_and_async_middleware def si simple_middleware(get_response): # One-time configuration and initialization goes here. if asyncio.iscoroutinefunction(get_response): async def middleware(request): # Do something0 码力 | 3184 页 | 3.14 MB | 1 年前3
共 18 条
- 1
- 2