Does django server support url callbacks (webhooks)?

931 views Asked by At

I am trying to implement url callbacks. And trying to test it. But seems like it is not working. I have been following this article for callbacks implementation.

I have defined two urls in 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'),
) 

and their views in 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')

Then I test from postman like

enter image description here

I am getting HTTP 200 OK response instead of getting 202 Accepted. What should I do for callback to work? Or am I missing something

1

There are 1 answers

1
domtes On

If your issue is to return a 202 HTTP status code instead of the default 200, you could try to use the status parameter as follows:

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