Я получаю эту ошибку, но не могу ее исправить, "Обратный для 'post_task' с аргументами '(' ',)' не найден. 1 шаблон (ы) пробовал: ['post / ajax / task / (? P [0-9] +) $ '] " У меня есть скрипт на моей главной странице , и когда я нахожусь на странице шаблона, все в порядке. но когда я go перехожу на любую другую страницу, включая главную, я получаю эту ошибку.
Вы можете мне помочь?
основной. html
<script>
if ($('#task-form').length > 0) {
// Exists.
$("#task-form").submit(function (e) {
// preventing from page reload and default actions
e.preventDefault();
// serialize the data for sending the form data.
var serializedData = $(this).serialize();
// make POST ajax call
$.ajax({
type: 'POST',
url: "{% url 'post_task' order.id %}",
data: serializedData,
success: function (response) {
// on successfull creating object
// 1. clear the form.
$("#task-form").trigger('reset');
// 2. focus to nickname input
$("#task").focus();
// display the newly friend to table.
var instance = JSON.parse(response["instance"]);
var fields = instance[0]["fields"];
$("#my_tasks tbody").prepend(
`<tr>
<td >${fields["task"] || ""}</td>
</tr>`
)
},
error: function (response) {
// alert the error if any error occured
alert(response["responseJSON"]["error"]);
}
})
})
}
$("#service-form").submit(function (e) {
// preventing from page reload and default actions
e.preventDefault();
// serialize the data for sending the form data.
var serializedData = $(this).serialize();
// make POST ajax call
$.ajax({
type: 'POST',
url: "{% url 'post_service' order.id %}",
data: serializedData,
success: function (response) {
// on successfull creating object
// 1. clear the form.
$("#service-form").trigger('reset');
// 2. focus to nickname input
$("#id_service").focus();
var total= $(".total").html(); //saving the total
$(".total").html(" ");
// display the newly friend to table.
var instance = JSON.parse(response["instance"]);
var fields = instance[0]["fields"];
$("#my_services tbody").append(
`<tr>
<td contenteditable="true">${fields["service"]||""}</td>
<td contenteditable="true">${fields["quantity"]||""}</td>
<td contenteditable="true">${fields["price"]||""} ₪</td>
<td>${total}</td>
<td><input type="submit" class="btn btn-danger justify-content-center text-center" value="מחק" /></td>
</tr>`
)
},
error: function (response) {
// alert the error if any error occured
alert(response["responseJSON"]["error"]);
}
})
})
Urls.py
from django.urls import path
from . import views
urlpatterns = [
path('register/', views.registerPage, name="register"),
path('login/', views.loginPage, name="login"),
path('logout/', views.logoutUser, name="logout"),
path('', views.home, name="home"),
path('products/', views.products, name="product"),
path('create_products/', views.product_create_view, name="productcreate"),
###customer###
path('customer/', views.indexView),
path('post/ajax/customer', views.postCustomer, name="post_customer"),
path('get/ajax/validate/name', views.checkCustomerName, name="validate_name"),
path('customer/<str:pk>/', views.customer, name="customer"),
###Order##
path('create_order/<str:pk>', views.createOrder, name="create_order"),
path('update_order/<str:pk>/', views.UpdateOrder, name="update_order"),
path('delete_order/<str:pk>/', views.deleteOrder, name="delete_order"),
path('post/ajax/order/', views.postOrder, name="post_order"),
##Tasks##
path('post/ajax/task/<int:id>', views.postTask, name="post_task"),
##services##
path('post/ajax/service/<int:id>', views.postService, name="post_service"),
path(r'delete_service/', views.deleteService, name="delete_service"),
#file
path(r'^upload/(?P<id>\d+)/$', views.upload_files, name='upload_picture'),
#info
path(r'^info/(?P<id>\d+)/$', views.order_info, name='order_info'),
]