django-ajax-post请求报错

原ajax请求写法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$.ajax({
type: "post",
url: "/tasks/addnewtask",
dataType: "json",
data: {
conf_name: conf_name,
conf_date: conf_date,
do_time: do_time
},
complete:function () {
},
success:function (data) {
if (data.status == 0){
location.reload()
} else {
alert(data.msg)
}
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});

请求提示:

1
2
3
4
5
6
RuntimeError at /tasks/addnewtaskYou called this URL via 
POST, but the URL doesn't end in a slash and you have
APPEND_SLASH set. Django can't redirect to the slash URL
while maintaining POST data. Change your form to point to
127.0.0.1:8000/tasks/addnewtask/ (note the trailing slash),
or set APPEND_SLASH=False in your Django settings.

修改:

在url末尾加上’/‘,修改为url: "/tasks/addnewtask/",,即可恢复正常

关于APPEND_SLASH配置项:

设置项是否开启URL访问地址后面不为/跳转至带有/的路径
APPEND_SLASH=True