我的资源代码是
class MessageResource(ModelResource):
class Meta:
queryset = Message.objects.all()
resource_name = "message"
always_return_data = True
authentication = ApiKeyAuthentication()
authorization = Authorization()
def determine_format(self, request):
return "application/json"
如果我得到没有任何身份验证信息的消息资源,则响应为
401 UNAUTHORIZED
"Content-Type" = "text/html; charset=utf-8";
Date = "Mon, 19 Nov 2012 15:36:28 GMT";
Server = "WSGIServer/0.1 Python/2.7.2";
而不是 html,我想获得 JSON 响应。实际上,我想知道在任何情况下如何指定tastepie 只发回JSON 响应?
我想得到像这样的 JSON 响应
{ "code": "401", "message": "Unauthorized" }
有没有办法实现它?