Core: get Json via POST

This commit is contained in:
Omma 2024-08-06 13:57:41 +03:30
parent 91f6fca9c8
commit 5892fb88f5
2 changed files with 26 additions and 3 deletions

View file

@ -1,5 +1,6 @@
from django.shortcuts import render
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import json
import requests
@ -10,11 +11,31 @@ def send_wells(request):
payload = {'data':[
{
"id": 1,
"licence": "12-d-13",
"license": "12-d-13",
},
{
"id": 2,
"licence": "16-a-111",
"license": "16-a-111",
},]
}
return JsonResponse(payload)
return JsonResponse(payload,status = 200)
@csrf_exempt
def create_well(request):
try:
print("creating wells")
data = request.POST
new_well = data.dict() # change querydict to dict
return JsonResponse({"data":[
{"error": "OK",
"created": new_well},
]},
status = 200
)
except Exception as e:
print(e)
return JsonResponse({"data":[
{"error": "Bad Request"}
]},
status = 400
)