Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse request in django

Hi i am making an webserver , In which I have to hit some request from html page and return the response. The URL which is generated using html is

http://192.168.2.253:8080/searchSMS/?KPImsgId=0&circle=&subId=&startDate=DD-MM-YYYY&endDate=DD-MM-YYYY&Username=ashish

but in the server side I am not able to see the request data. I am using q = QueryDict(request.body) but it is showing <QueryDict: {}>

How to find the all the parameters coming in request.

like image 394
Ashish Kumar Verma Avatar asked Dec 23 '15 07:12

Ashish Kumar Verma


1 Answers

In your case you send the data in url so access the data through request.GET as follow:

username = request.GET.get('Username')
start_date = request.GET.get('startDate')
# ... the same for all the other parameter after the `?` marque.

In fact there is a difference between request data, request.body, request.GET and request.POST:

  • If you are sending POST request to django function view or class based view: you access the request data in request.body or request.POST.
  • If you are sending POST request to Django REST Framework: you access the data in request.data. You may also find in Internet request.DATA that correct but it's deprecated in the newer version of DRF in favor of request.data.
  • If you send parameter in the url like in you case, you access the data form request.GET as explained above.
like image 131
Dhia Avatar answered Oct 17 '22 13:10

Dhia