Request POST in Django with AJAX function in Angular

0

I'm doing an AJAX function in angular where I pass a value for POST and it returns an object in JSON.

My AJAX function is this:

$http.post('/get_professional_info/', {idProfessional: id}).then(
        function mySucces(response) {
            // Hago mis cosas
        }, function myError(response) {
            // Informo error
        });

In views.py I put the following:

def get_professional_info(request):
    dic_id = request.POST['idProfessional']
    professional = Profesional.objects.filter(id_profesional = int(idPro))
    # El resto de las cosas...

The issue is that debugging I see that the information is being sent correctly. When I print the request.POST, this appears to me, which is defined as a QueryDict:

{'{"idProfessional":3}': ''}

How am I supposed to access that? I already tried with

request.POST['idProfessional']

and

request.POST.dict()['idProfessional']

And none works.

    
asked by Genarito 02.11.2016 в 19:24
source

1 answer

0

There I solved the problem with this excellent Gist developed by Gaspar Dzul. The explanation and how to use it can be seen here . Apparently Django with Angular are conflicting by JSON syntax and parsing theme. With that I just spent enough and enough to solve the problem.

    
answered by 04.11.2016 / 17:06
source