我很感激我的网址设置错误,我会很感激的。在
<div id='notificationsLoader'>
</div>
<script>
$(document).ready(function(){
$(".notification-toggle").click(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"{% url 'get_notifications_ajax' %}",
data: {
csrfmiddlewaretoken: "{{csrf_token}}",
},
success: function(data){
$("#notificationsLoader").html('<h3>notifications</h3>');
$(data.notifications).each(function(){
$("notificationsLoader").append(this + "<br/>")
})
console.log(data.notifications);
},
error: function(rs, e){
console.log(rs);
console.log(e);
}
})
})
})
</script>
在视图.py
^{pr2}$在网址.py
urlpatterns += patterns('notifications.views',
url(r'^notifications/$', 'all', name='notifications_all'),
url(r'^notifications/ajax/$', 'get_notifications_ajax', name='get_notifications_ajax'),
url(r'^notifications/(?P<id>\d+)/$', 'read', name='notifications_read'),
)
我试过在我的设置.py但这行不通。我几乎可以肯定代码是正确的,因为我遵循的是一个教程,有了这段代码,讲师可以毫无问题地完成它。谢谢你
完全错误
POST http://127.0.0.1:8000/notifications/ajax/ 403 (FORBIDDEN)> ERROR)send @ jquery.min.js:4m.extend.ajax @ jquery.min.js:4(anonymous function) @ (index):359m.event.dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3
您的数据使用的是一个
csrf_token
上下文变量,我猜您还没有设置,您更可能希望使用django模板标记作为令牌除此之外,500错误是服务器错误,在调试和开发时,您应该将
DEBUG
设置设置为true来获取更多信息错误。在相关问题 更多 >
编程相关推荐