Django:创建 webhook 接收器
Django: Create webhook receiver
我目前正在尝试为 this site 实施 webhook。我在有关创建 webhook 的文档中找不到太多信息。您是否有任何好的存储库或页面我可以查看以更好地了解如何为 Typeform 构建 webhook?
正如 Daniel 在他们的评论中指出的那样,webhook 接收器只是 Django 应用程序中的另一个端点,接受 POST 请求并处理 JSON 输入。
我尝试整理了一个示例,希望对您有所帮助。
import json
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
@csrf_exempt
@require_POST
def webhook_endpoint(request):
jsondata = request.body
data = json.loads(jsondata)
for answer in data['form_response']['answers']: # go through all the answers
type = answer['type']
print(f'answer: {answer[type]}') # print value of answers
return HttpResponse(status=200)
我目前正在尝试为 this site 实施 webhook。我在有关创建 webhook 的文档中找不到太多信息。您是否有任何好的存储库或页面我可以查看以更好地了解如何为 Typeform 构建 webhook?
正如 Daniel 在他们的评论中指出的那样,webhook 接收器只是 Django 应用程序中的另一个端点,接受 POST 请求并处理 JSON 输入。
我尝试整理了一个示例,希望对您有所帮助。
import json
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
@csrf_exempt
@require_POST
def webhook_endpoint(request):
jsondata = request.body
data = json.loads(jsondata)
for answer in data['form_response']['answers']: # go through all the answers
type = answer['type']
print(f'answer: {answer[type]}') # print value of answers
return HttpResponse(status=200)