Fatched value of json content_type and heard

This commit is contained in:
Apalak Dutta 2023-06-04 22:03:32 +05:30
parent 4e1c38c0ed
commit 73e024cc8a
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,14 @@
import json
from django.http import JsonResponse from django.http import JsonResponse
def api_home(request,*args,**kwargs): def api_home(request,*args,**kwargs):
return JsonResponse({"message":"This is my 1st Django api project"}) body = request.body # byte string of Json data
data = {}
try:
data = json.loads(body) #string of json data ---> python dict
except:
pass
data['headers'] = dict(request.headers)
data['content_type'] = request.content_type
print(data)
return JsonResponse(data)

View File

@ -1,7 +1,7 @@
import requests import requests
endpoint = "http://127.0.0.1:8000/api/" endpoint = "http://127.0.0.1:8000/api/"
get_response = requests.get(endpoint,json={"query": "Hello world"}) #HTTP Request get_response = requests.get(endpoint,params={"abc":123}, json={"query": "Hello world"}) #HTTP Request
print(get_response.text) # print raw text response #print(get_response.text) # print raw text response
print(get_response.json()['message']) print(get_response.json())
print(get_response.status_code) print(get_response.status_code)