Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
How to add more fields to the return response in django rest framework

I am trying to add more fields to the Response in the django rest framework to send to react frontend.

This works fine

@api_view(('GET',))
def get_status(request, task_id):
    task = current_app.AsyncResult(task_id)

    response_data = ImageSerializer(Image.objects.get(pk=task.get()))

    return Response(response_data.data, status=status.HTTP_201_CREATED)

How can I add the json context below to the Response also?

#How can I add the following to my response too
context = {'task_status': task.status, 'task_id': task.id}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can add the extra data with:

@api_view(('GET',))
def get_status(request, task_id):
    task = current_app.AsyncResult(task_id)

    response_data = ImageSerializer(Image.objects.get(pk=task.get()))
    context = {'task_status': task.status, 'task_id': task.id}

    return Response({**context, **response_data.data}, status=status.HTTP_201_CREATED)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda