Ajax url 带参数。当前路径与这些路径都不匹配

Ajax url with parameter. The current path didn’t match any of these

我是 django 的新手。我尝试通过 ajax 调用从数据库中删除元素。我的 ajax 调用发送 url,参数是要删除的元素的 pk。 Url 看起来不错,但浏览器会引发错误 url 模式与我的 url.py 中的任何 url 模式都不匹配。 我以前做过类似的项目,一切都很好,所以我很困惑为什么它现在不起作用。有什么想法吗?

urls.py:

urlpatterns = [
    path('', views.home,name='home'),
    path('mojerec',views.mojeRec,name='mojerec'),
    path('dodajrec',views.dodajRec,name='dodajrec'),
    path('receptura/(<int:receptura_id>)',views.receptura,name='receptura'),
    path('formJson/<str:skl>/', views.formJson, name='formJson'),
    path('receptura/formJson/<str:skl>/', views.formJson, name='formJson'),
    path('receptura/dodajskl/<str:sklId>/', views.dodajsklJson, name='dodajsklJson'),
    path('receptura/aktualizujTabela/<str:sklId>/', views.aktualizujTabela, name='aktualizujTabela'),
    path('receptuta/delSkl/<int:id>/', views.delSkl, name='delSkl'),


]

views.py

def delSkl (request,id):
    deletedElement=Skladnik.objects.filter(pk=id)
    response=serializers.serialize("python", deletedElement)
    deletedElement.delete()
    print('response', response)
    sys.stdout.flush()
    return JsonResponse({'response':response})

myjs.js

function usuwanieSkladnika (pk){
        $.ajax({
                        type: 'GET',
                        url: `delSkl/${ pk }/`,
                        success : function(response){console.log('sukces ajaxa z del');
                        cardBox.innerHTML=''
                        tabelaDocelowa.innerHTML='';
                        updateTable()

                        },//koniec sukcesa
                        error : function (error){console.log('brak sukcesu ajaxa z del')},
                        })

}

日志:

Page not found (404)
Request Method:     GET
Request URL:    http://localhost:8000/receptura/delSkl/13/

Using the URLconf defined in recipe.urls, Django tried these URL patterns, in this order:

    admin/
    [name='home']
    mojerec [name='mojerec']
    dodajrec [name='dodajrec']
    receptura/(<int:receptura_id>) [name='receptura']
    formJson/<str:skl>/ [name='formJson']
    receptura/formJson/<str:skl>/ [name='formJson']
    receptura/dodajskl/<str:sklId>/ [name='dodajsklJson']
    receptura/aktualizujTabela/<str:sklId>/ [name='aktualizujTabela']
    receptuta/delSkl/<int:id>/ [name='delSkl']
    users/

The current path, receptura/delSkl/13/, didn’t match any of these.

您的 urls.py 中有拼写错误,即您的 urls.py 中有 receptuta/delSkl/<int:id>/ 并且您正在调用 receptura/delSkl/<int:id>/

将您的 urls.py 更改为:

path('receptuta/delSkl/<int:id>/', views.delSkl, name='delSkl'),

为此:

path('receptura/delSkl/<int:id>/', views.delSkl, name='delSkl'),