Skip to content Skip to sidebar Skip to footer

Ajax Call Is Not Going To View Function Django

Hi I am sending request to a django view but its not accessing view function . Both are in same app . And I am using debugging tool so I tried to debug but on my view no call is r

Solution 1:

You can see live demo here REPL

First do this if you don't want that your view check the csrf token. This can be done by using decorator @csrf_exempt.

view.py

from django.views.decorators.csrf import csrf_exempt

@csrf_exemptdefedit_profile(request):
    print(request)
    if request.method == 'GET':
        return render(request, 'authenticate/edit_profile.html')

url.py

path('edit_profile/', views.edit_profile , name="edit_profile"),

ajax request

$.ajax({
    url: '/edit_profile/',
    type: 'GET',// This is the default though, you don't actually need to always mention itdata:{},
    success: function(data) {
        alert(data);
    },
    failure: function(data) { 
        alert('Got an error dude');
    }
});

Post a Comment for "Ajax Call Is Not Going To View Function Django"