[Fixed]-How to insert data into django app database using a web API

1👍

You can send data from the Python Script to the backend. You will need to have in place an API defined in Django, of course. But assuming you already have it you can simply use the awesome requests library to send the data from the Script:

>>> r = requests.get('http://localhost:8000/v1/api/resource?param1=12&param2=blabla')

Or using POST:

>>> payload = {'key1': 'value1', 'key2': 'value2'}

>>> r = requests.post('http://localhost:8000/v1/api/resource', data=payload)

And the Backend will receive it (If you are using Django you will need to process it in the View, and most probably use the ORM to store the value). If by any chance you don’t receive the value in the View, it means that the APIs defined in the urls.py file are probably not configured correctly.

Leave a comment