Need example view on how to react on a webhook in Django

182 views
Skip to first unread message

Sabine Maennel

unread,
Oct 16, 2015, 10:24:21 AM10/16/15
to Django users
Hello,

I tried to followed this Tutorial from Go Django, but I do not get it to work. Can you please help me on how to react on a webhook in my application.

This is the tutorial, that I tried to follow: https://godjango.com/55-webhooks-django-and-ngrok/

This is my view:
# coding: utf-8

from __future__ import unicode_literals, absolute_import

import json

from django.views.generic import View

from braces.views import CsrfExemptMixin

import logging
logger = logging.getLogger(__name__)

class ProcessHookView(CsrfExemptMixin, View):
def post(self, request, args, *kwargs):
print(json.loads(request.body))
return HttpResponse()

url file: 
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.conf.urls import patterns, include, url
from .providers.hook import ProcessHookView, test_view, my_webhook_view


urlpatterns = patterns('',

url(r'^test$',
ProcessHookView.as_view()),

)


The view does not work: I tried to call it with: 

curl -X POST http://127.0.0.1:8000/de/webhooks/x -d '{"foo": "bar"}'


and get this error:

[16/Oct/2015 16:09:57] "POST /de/webhooks/test HTTP/1.1" 500 112859


if I try the url directly I get this error:

[16/Oct/2015 16:10:20] "GET /de/webhooks/test HTTP/1.1" 405 0


What am I doing wrong? Is there an example on how to do it right? Do I need Celery for this?

Any help is highly appreciated

with kind regards

Sabine Maennel

Daniel Roseman

unread,
Oct 18, 2015, 8:27:31 AM10/18/15
to Django users
Looks like the post you are following had a formatting problem, maybe thanks to conversion from Markdown. The signature of the `post` method should be:

    def post(self, request, *args, **kwargs):

ie one asterisk before args, and two for kwargs.

Celery has nothing to do with this sort of thing - it's for offline processing. You might well want to trigger a Celery task from your webhook receiver, especially if the sender is expecting a quick response, but it's not required.
-- 
DR.
Reply all
Reply to author
Forward
0 new messages