0

On a server, I have a Django app with a database. At the client, I am writing a Python script to send data through https to the server and have the server insert that data into the database.

How should I approach this problem? I am in control of both the server and the client. The reason for wanting to do this is to have an API to insert data into the database.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Wouldn't that allow unauthorized users to insert data and use up all the storage space on the server?
Well, if you plan to put it on the Internet and it's just not something to be used locally, you will have to set up an Auth mechanishm. For such simple application you can simply pass a Token by POST, that it's validated by Django. This way only requests with that Token are allowed to store that information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.