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

184
Visualizações
Security using Django 1.10 + AJAX without any HTML form

I make a POST request via AJAX without HTML form. Are there any security issues? Why is there no csrf error? Because I do not send any csrf data and csrf is enabled in django?

toggle-status.js

jQuery(document).ready(function($) {
    $("#switch-status").click(function(){
    $.ajax({
        url: '/account/switches/',
        data: {'toggle': 'status'}
    });
    });
});

view.py

@login_required
def switches(request):
    toggle = request.GET.get('toggle', None)
    current_user = request.user
    update = Switches.objects.get(owner=current_user)
    if toggle == 'status':
    if update.status is True:
        update.status = False
    else:
        update.status = True
    update.save()
    return HttpResponse('')
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The default method of the ajax function is a GET one, not a POST. So, doing a:

$.ajax({
    url: '/account/switches/',
    data: {'toggle': 'status'}
});

implies that an ajax GET is made. So, you're not doing a POST request.

If you want a POST request, do it like this:

$.ajax({
    method: 'POST',
    url: '/account/switches/',
    data: {'toggle': 'status'}
});

Of course you have to include the CSRF token then, since it will fail if you try to POST without including one. Look here how to acomplish that.

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