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

599
Visualizações
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 Respostas
Responde à pergunta

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 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