현재 Tastypie에 대한 인증을 사용하고 있지는 않지만 브라우저에서 URL로 이동하면 내용을 볼 수 있습니다.401 Tastypie API를 사용하여 jquery get 메서드로 UNAUTHORIZED 오류가 발생했습니다.
http://localhost:8000/live/api/update/?format=json
하지만 내가 JQuery와 아약스 호출을 통해 페이지에서이 데이터를 얻기 위해 노력하고, 브라우저 불을 지르고 콘솔에서
$.post('/live/api/update/?format=json',
{type:'GET',dataType: "json", processData: false,
contentType: "application/json",userid:$('#index').val()},function(devicelist){
.....
}
, 나는 401
주를보고 M : 하리스의 대답에서 나는이 문제를 해결할 수 있었다, 그러나
을 작동 왜 내가 사용할 때 원하는
$.ajax({ type: "POST", url: url, data: data, success: success, dataType: dataType });
이 (상태 : 202)가 작동 중이면 내가 PHP를 사용할 때 나는이 working.Actually없는 내가 장고에 내 PHP 코드를 이동
$.post('/live/api/update/?format=json',
{type:'GET',dataType: "json", processData: false,
contentType: "application/json",userid:$('#index').val()},function(devicelist){
.....
}
를 사용할 때 반면, 사용하는 위의 코드는 401 오류와 함께 작동합니다
api.py
from tastypie.resources import ModelResource
from models import Update
from tastypie.serializers import Serializer
import urlparse
class urlencodeSerializer(Serializer):
formats = ['json', 'jsonp', 'xml', 'yaml', 'html', 'plist', 'urlencode']
....
class UpdateResource(ModelResource):
class Meta :
queryset = Update.objects.all()
resource_name = 'update'
filtering = {'imei' : ALL }
#authentication = DjangoCookieBasicAuthentication()
serializer = urlencodeSerializer() # IMPORTANT
allowed_methods = ['get','post']