我在Apache上運行一個Django站點,它由Nginx實例作爲前端來服務我的靜態媒體。django-tastypie PATCH給我一個「400(Bad Request)」
我通過django-tastypie公開了一個API來模擬我需要修補的字段。當我做本地測試時(通過django 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()
如何解決這所有的方向可以理解的:)
你想要修補的URL是什麼? api/v1/message /或api/v1/message/1 /? – santiagobasulto 2012-08-13 10:42:46
我正在嘗試修補/ api/v1/message/1 /仍然沒有快樂。我看到這個[post](http://stackoverflow.com/questions/10069871/heroku-and-django-with-405-error),似乎表明我需要對Nginx做些事情,但對於我的生活,我不能找到那是什麼: -/ – 2012-08-13 16:49:16
你應該開始嘗試去實現問題是什麼「層」。如果它在你的HTTP服務器上或你的應用程序中(Tastypie)。嘗試刪除身份驗證和授權,並進行一些測試。此外,將此添加到您的Meta類:detail_allowed_methods = ['patch'] – santiagobasulto 2012-08-13 17:21:29