0

Does anyone have any examples on how I can make my DRF class based modelviews async? Reading the Django docs it says...

Any view can be declared async by making the callable part of it return a coroutine - commonly, this is done using async def. For a function-based view, this means declaring the whole view using async def. For a class-based view, this means making its call() method an async def (not its init() or as_view()).

I have class based views, so what I was hoping was there were examples on the correct syntax to implement the async on the call() method so that I can try and make my view async to make use of Django's async support. Now, there are examples of implementing an async view if it's a function based view, meaning making the as_view() for example async How to use async function based views in DRF?

Unfortunately, I haven't found any examples as of yet for implementing this for class based views.

Given this, I was also hoping there are examples of how I can unit test my new async class based views. I've been using APITestCase and unittest.mock to run and patch various tests on my sync views, but this doesn't support testing a coroutine, so the tests fail.

2
  • I think that no body know what you exactly mean. You need to define problem, use case or any other example / goal what you want to achieve. Maybe you mean websockets i dont know... Commented Oct 26, 2021 at 19:36
  • Ok thanks mon io, let me update my initial question. Commented Oct 27, 2021 at 13:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.