Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

362
Visualizações
Correct way to use async class based views in Django

I am trying to use the very new Django 3.1 Async view classes. Based on the limited documentation available, I have tried to create my own async def __call__() method. From the documents:

For a class-based view, this means making its __call__() method an async def (not its __init__() or as_view()).

Django 3.1 Development Documents

However, until now I have had no luck with writing an asynchronous class based view. I constantly get await exceptions, or asyncio.iscoroutinefunction returns False, which I assume should return true if the class is actually Asynchronous.

Since the documentation is lacking an example, could someone with more knowledge of async programming help me with an example of a class based asynchronous view?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Spend quite some time searching in the Django ticket system, blogposts (thx to Joren), etc. so you don't have to.

The best you can do is using the code from the blog:

class YourView(View):    
@classonlymethod
def as_view(cls, **initkwargs):
    view = super().as_view(**initkwargs)
    view._is_coroutine = asyncio.coroutines._is_coroutine
    return view

async def get(self, *args, **kwargs):
    ...

But you also need to be aware there is no way you can use actual generics (no async ORM support, even TemplateView doesn't work) and build-in decorators for 3.1. You need to write your own stuff for things that Django normally does itself.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda