我正在尝试测试我的 API,但我以前从未遇到过这个问题。我收到错误:No JSON object could be decoded
。我真的被困住了,不胜感激。我什至不确定如何调试它们。
这只发生在“POST”
这是我的 API
from reflection.feedback.models import Feedback
from django.contrib.auth.models import User
from tastypie import fields
from tastypie.api import Api
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.exceptions import NotFound
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
class DjangoAuthentication(Authentication):
"""Authenticate based upon Django session"""
def is_authenticated(self, request, **kwargs):
return request.user.is_authenticated()
class CommonMeta:
authentication = DjangoAuthentication()
authorization = Authorization()
always_return_data = True
class UserResource(ModelResource):
class Meta(CommonMeta):
queryset = User.objects.all()
resource_name = 'user'
excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser']
filtering = {
'username': ALL,
}
class FeedbackResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user')
class Meta(CommonMeta):
queryset = Feedback.objects.all()
resource_name = 'feedback'
excludes = ['created',]
allowable_methods = ['post',]
filtering = {
'user': ALL_WITH_RELATIONS
}
def obj_create(self, bundle, request=None, **kwargs):
return super(FeedbackResource, self).obj_create(bundle, request)