今天在学习ajax时总是报错误,弄的我一头雾水
RuntimeError: You 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/app02/text_ajax/ (note the trail
首先ajax的脚本写法引用是这样的
$.ajax({ url:'/app02/text_ajax', type:"POST", data:{'hostname':$('#host').val(),'ip':$('#ip').val(),'port':$('#port').val(),'b_id':$('#sel').val()}, success:function(data){ if(data == "OK"){ location.reload() }else{ alert(data); } } })
看着没问题,而urls文件的路径是如下写的
urlpatterns = [ path('admin/', admin.site.urls), path('business/', views.business), path('orm/', views.orm), path('host333/', views.host333), path('text_ajax', views.text_ajax), ]
注意text_ajax后面不能加/,因需要访问资源,APPEND_SLASH的值是Ture
所以要么不加/,要么把APPEND_SLASH的值改为False,我是前面那种。