저는 REST API 요청을 처리하기 위해 django에서 tastypie를 사용했습니다. 내가 GET/POST 요청을 할 때, 기본적으로 메소드를 dehydrate하게됩니다. 그러나 DELETE/PUT 요청에는 tastypie가 처리하는 메소드가 없으므로 요청 정보를 기록 할 수있는 방법이 없습니다.tastypie django에서 모든 요청을 기록하는 방법
class ProjectResource(ModelResource):
allowed_methods = ['get', 'put', 'post', 'delete']
resource_name = 'project'
queryset = Project.objects.all()
validation = FormValidation(form_class=ProjectForm)
always_return_data = True
filtering = {
'id': ALL,
'slug': ALL,
}
def dehydrate(self, bundle):
import pdb;pdb.set_trace() #--> get/post request hit this function
logger.log('app.main','debug', 'Project info', bundle)
bundle.data['name'] = cgi.escape(bundle.obj.name)
return bundle
tastypie.resource 모듈에서 ModelResource를 무시하는 함수가 있습니까? 모든 요청에 대해 먼저 번들 데이터를 얻은 다음 처리되기 전에 로거에 전달합니다.
요청이 아직 라우팅되지 않은 경우 WSGI 미들웨어 수준에서 로그 할 수 없습니까? 또는 [Django 미들웨어] (https://docs.djangoproject.com/en/1.10/topics/http/middleware/) 수준에서? 필요한 모든 요청이 있고 API URL의 모양 (예 :'.startswith ('/ api /') ')이 있으면 충분할 수 있습니다. – 9000