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

598
Vistas
AJAX call to Django View returns None to data

I have been trying to get data that I send using AJAX with a Django view. I have this AJAX call

$.ajax({
    method: "POST",
    url: "{% url 'change_publish_status' %}",
    value: {"company_id": company_id, "published": published},
    dataType: 'json',
    headers: {"X-CSRFToken": '{{ csrf_token }}'}
});

and I'd like to access the company_id and the published variables from the django view. I have tried many things

  • self.request.POST.get('company_id') --> returns None
  • self.request.POST.get('company_id', None) --> returns None
  • self.request.body --> returns b''

This is my view right now

@method_decorator(login_required, name='dispatch')
class ChangePublishStatus(TemplateView):
    def post(self, *args, **kwargs):
        company_id = self.request.POST.get('company_id', None)
        published_status = self.request.POST.get('published') == "true"

        print(company_id)

        return JsonResponse({"status": "ok"})

    def get(self, *args, **kwargs):
        return redirect("list")
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

To send the data in the POST call, pass the data in the data argument rather than value.

$.ajax({
    method: "POST",
    url: "{% url 'change_publish_status' %}",
    data: {"company_id": company_id, "published": published},
    dataType: 'json',
    headers: {"X-CSRFToken": '{{ csrf_token }}'}
});
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