我使用Ajax請求我tastypie資源,但即使我用SessionAuthentication()和DjangoAuthorization(),它會永遠401Django的Tastypie總是返回401未經授權
resources.py
class EventsResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Event.objects.all()
resource_name = 'events'
filtering = {'start': ALL,
'end':ALL
}
list_allowed_methods = ['get', 'post','put', 'patch']
detail_allowed_methods = ['get', 'post', 'put', 'delete']
authentication = SessionAuthentication()
authorization = Authorization()
include_resource_uri = True
limit = 0
always_return_data = True
這是一個日曆的資源,所以我有一個事件模型,並且我的ajax請求在django-admin中加載的javascript文件中;我還檢查了請求標頭是否有csrf標記和會話標識,但不起作用。
.ajax({
url: event.resource_uri,
dataType: 'json',
contentType: 'application/json; encode=UTF-8',
type: 'DELETE',
success: function() {
$calendar.fullCalendar('removeEvents');
$calendar.fullCalendar('refetchEvents');
$('#modal-confirm').modal('hide');
showmsg('Evento eliminato correttamente', 'warning');
}
});