Abu bakr
Abu bakr

Reputation: 79

Django how to use webhook and post data?

i am confused about django webhooks because i am beginner in python and django. Most of the things i see for the documentation. how do i connect to my app and Post data.Can anyone tell me how do i set my webhook for my data. i want to Post data to zapier.

Models.py

class Driver(models.Model):
    class Meta():
        db_table = "driver"
        verbose_name = "Driver"
        verbose_name_plural = "Drivers"
        ordering = ['driver_firstname', 'driver_lastname']

    driver_firstname = models.CharField(
        max_length=64,
        blank=True,
        null=True
    )
    driver_lastname = models.CharField(
        max_length=64,
        blank=True,
        null=True
    )

    driver_email= models.CharField(
        max_length=64,
        blank=True,
        null=True

    )

Views.py

def drivers(request):
    if request.method == 'POST':
        if request.POST['driver_firstname'] and request.POST['driver_lastname'] and request.POST['driver_email']
            driver = Driver()
            driver.driver_firstname = request.POST['driver_firstname']
            driver.driver_lastname = request.POST['driver_lastname']
            driver.driver_email = request.POST['driver_email']
            driver.save()

Upvotes: 1

Views: 1691

Answers (1)

Aurélien
Aurélien

Reputation: 1655

If you want to post data outside of your app, you can take a look to HTTP library Requests

For example:

import requests

driver_firstname = request.POST['driver_firstname']
driver_lastname = request.POST['driver_lastname']
driver_email = request.POST['driver_email']

payload = {'driver.driver_firstname': driver_firstname,
           'driver.driver_lastname': driver_lastname,
           'driver.driver_email': driver_email
           }

r = requests.post("http://your-url.org/post", data=payload)

Upvotes: 3

Related Questions