I have a device that do some calculations and then i want to send it with help of request to my site:
import requests
params = {'data1': '47237582'}
r =requests.get("http://127.0.0.1:8000/", data = params)
print(r)
I have a django site. How can i save the value of my request for later display?
def read(request):
if request.method == 'GET':
msg = request.GET['data1']
And how can i save it to database?
CodePudding user response:
- First, create a model called Message, fields maybe: msg and from, it actually depends on how you want to store the msg,
- Then after getting the msg with
msg = request.GET['data1']
store the msg withmsg_obj = Message.objects.create(msg=msg, ...other-fields if any)
CodePudding user response:
If you are gonna have different keys (i.e columns) for each request, then I say you use MongoDB, which will allow you save different set of key-values in a single document.