Answer the question
In order to leave comments, you need to log in
How to correctly make django urls for ajax request?
Good afternoon. There is a js file in which an asynchronous request is executed, it is planned to connect it to different pages.
function calculateFingerprint(){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'fingerprinter/fingeprint', false);
xhr.send(fingerprint);
if (xhr.status != 200) {
console.log( xhr.status + ': ' + xhr.statusText );
} else {
return xhr.responseText;
}
};
from django.contrib import admin
from django.urls import path, include
from fingerprinter import views
urlpatterns = [
path('admin/', admin.site.urls),
path('fingerprinter/', include('fingerprinter.urls')),
path('', views.index, name='index'),
]
urlpatterns = [
path('', views.index, name='index'),
path('fingeprint', views.calculate_fingerprint, name='calculate_fingerprint'), #Сюда ajax хочу принимать
]
django-fingerprint.js:247 POST http://localhost:8000/fingerprinter/fingerprinter/fingeprint 404 (Not Found)
Answer the question
In order to leave comments, you need to log in
I won’t tell you what the problem is right off the bat, but I will recommend the battery https://pypi.org/project/django-extensions/ - I have it in every project by default. Connect it, and in addition to any usefulness, you will have the following management command:
manage.py show_urls
I think everything will clear up right away!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question