나는 정적 인 미디어를 제공하기 위해 Nginx 인스턴스에 의해 front'ed 인 Apache에서 Django 사이트를 실행하고 있습니다.django-tastypie PATCH는 "400 (Bad Request)"을 제공합니다
필드를 패치해야하는 모델에 django-tastypie를 통해 API를 노출합니다. 장고 runserver를 통해 로컬 테스트를 수행하면 모든 것이 예상대로 작동합니다. 그러나 라이브 서버에서는 "400 (Bad Request)"이 반환됩니다.
Nginx가 Patch를 지원하지 않는다고 말하는 곳을 몇 군데 읽었습니까? 그게 맞습니까? 이것에 대한 좋은 해결 방법이 있습니까? 내가 뭔가 잘못하고 있는거야?
postData을 통해 업데이트하려는 필드를 통해서만 전송합니다.
JQuery와 코드 :
$.ajax({url: '...',
type: 'PATCH',
accepts: 'application/json',
contentType: 'application/json',
dataType: 'json',
data: postData,
processData: false,
success: function() {
// Success Code!
},
error: function() {
// Error Code!
}
});
Tastypie 리소스 :
class ReceivedMessageResource(ModelResource):
"""
"""
campaign = fields.ForeignKey(CampaignResource, 'campaign')
campaign_name = fields.CharField(readonly=True)
campaign_id = fields.IntegerField(readonly=True)
message_type = fields.CharField(readonly=True)
display_date = fields.CharField(readonly=True)
attachments = fields.ToManyField('apps.campaign.api.AttachmentResource',
'attachment_set',
related_name='message',
full=True)
class Meta:
queryset = ReceivedMessage.objects.all()
resource_name = 'message'
filtering = {'id': ALL,
'campaign': ALL_WITH_RELATIONS}
excludes = ['reason', 'provider', 'loyalty_profile', 'original_message', 'date_received']
allowed_methods = ['get', 'post', 'put', 'delete', 'patch']
paginator_class = ReceivedMessagesPaginator
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
이를 정렬하는 방법에 대한 방향을 이해할 수있을 것이다
: PATCH가
패치 할 URL은 무엇입니까? api/v1/message/또는 api/v1/message/1 /? – santiagobasulto
패치/api/v1/message/1/아직 기쁨이 없습니다. 나는이 Nginx에 뭔가를 할 필요가 있다고 생각하는 것처럼 보이는이 post (http://stackoverflow.com/questions/10069871/heroku-and-django-with-405-error)를 보았습니다. 그러나 저의 삶을 위해서 나는 할 수 없습니다. -/ –
문제가 "계층"인지 파악하기 시작해야합니다. HTTP 서버 또는 응용 프로그램 (Tastypie)에있는 경우인증 및 허가를 제거하고 몇 가지 테스트를 해보십시오. 또한, 이것을 Meta 클래스에 추가하십시오 : detail_allowed_methods = [ 'patch'] – santiagobasulto