You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api-guide/views.md
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -217,6 +217,22 @@ You may pass `None` in order to exclude the view from schema generation.
217
217
def view(request):
218
218
return Response({"message": "Will not appear in schema!"})
219
219
220
+
# Async Views
221
+
222
+
When using Django 4.1 and above, REST framework allows you to work with async class and function based views.
223
+
224
+
For class based views, all handler methods must be async, otherwise Django will raise an exception. For function based views, the function itself must be async.
225
+
226
+
For example:
227
+
228
+
class AsyncView(APIView):
229
+
async def get(self, request):
230
+
return Response({"message": "This is an async class based view."})
231
+
232
+
233
+
@api_view(['GET'])
234
+
async def async_view(request):
235
+
return Response({"message": "This is an async function based view."})
0 commit comments