Reputation: 613
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 received and My ajax call code is like this
$.ajax({
url: '/edit_profile/',
type: 'get', // This is the default though, you don't actually need to always mention it
success: function(data) {
alert(data);
},
failure: function(data) {
alert('Got an error dude');
}
});
url.py
path('edit_profile/', views.edit_profile , name="edit_profile"),
view.py
def edit_profile(request):
print(request)
print(request)
if request.method == 'POST':
return render(request, 'authenticate/edit_profile.html', context)
I am debugging but call is not received in this view function .
Upvotes: 1
Views: 1504
Reputation: 2498
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_exempt
def edit_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 it
data:{},
success: function(data) {
alert(data);
},
failure: function(data) {
alert('Got an error dude');
}
});
Upvotes: 3