About Posting JSON Data from a Django Website to Another Website

You can post JSON data from a Django website to another website using requests library:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import json
import requests
from django.core.serializers.json import DjangoJSONEncoder

response = requests.post(
    url="https://example.com/webhook/",
    json=json.loads(json.dumps(data, cls=DjangoJSONEncoder)),
    headers={"Content-type": "application/json"},
)
if response.status_code == requests.codes.ok:
    # proceed...

Tips and Tricks Programming Development Python 3 requests JSON