django服务器是否支持url回调(webhooks)?

时间:2015-06-05 08:03:54

标签: django url callback webhooks

我正在尝试实现url回调。并尝试测试它。但似乎它不起作用。我一直关注this文章的回调实现。

我在urls.py中定义了两个网址

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^agent205', 'agent205.views.test'),
    url(r'^agent206', 'agent205.views.test2'),
) 

及其在views.py中的观点

__author__ = 'rai'
from django.shortcuts import HttpResponse, render_to_response, render
from  django.http.request import HttpRequest
import urllib, urllib2, json
from django.contrib.auth.decorators import login_required
import json
from rest_framework.views import APIView
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def test(request):
    data = {'foo': 'bar', 'hello': 'world'}
    print request.body
    return HttpResponse(json.dumps(data), content_type='application/json')

@csrf_exempt
def test2(request):
    return HttpResponse(json.dumps(request.body), content_type='application/json')

然后我从邮递员那里测试

enter image description here

我收到HTTP 200 OK响应而不是202 Accepted。回调工作应该怎么办?或者我错过了什么

1 个答案:

答案 0 :(得分:2)

如果您的问题是返回202 HTTP状态代码而不是默认200,您可以尝试使用status参数,如下所示:

@csrf_exempt
def test(request):
    data = {'foo': 'bar', 'hello': 'world'}
    print request.body
    return HttpResponse(json.dumps(data), content_type='application/json', status=202)