I have a django app with views file set up as
def SomeView(response):
if response.method == 'GET':
data = response.GET.get("test")
return HttpResponse(data)
and another python file i am using to make requests to my local django app like
import requests
payload = {'test': 1}
r = requests.get("127.0.0.1:8000" , data = payload)
print(r.text)
Basically i would like to return a http response based on the data sent through GET request so expected output is:
1
but the actual out i recieve is
None
Please guide me towards the correct way to do it.
CodePudding user response:
To encode data in the query string [wiki], you should use the params=…
parameter [requests-doc], not :data=…
import requests
payload = {'test': 1}
r = requests.get('127.0.0.1:8000', params=payload)
print(r.text)