Core: get Json via POST
This commit is contained in:
		
							parent
							
								
									91f6fca9c8
								
							
						
					
					
						commit
						5892fb88f5
					
				
					 2 changed files with 26 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -3,4 +3,6 @@ from .views import *
 | 
			
		|||
 | 
			
		||||
urlpatterns = [
 | 
			
		||||
    path('get/', send_wells, name='send_wells'),
 | 
			
		||||
    path('create/', create_well, name='create_well'),
 | 
			
		||||
 | 
			
		||||
]
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
        )
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue