I’m new in working with python and Django. I want to write a web service in django that receives some input parameteres and return back a response. This web service is supposed to get called from an iOS app. I wrote the below method but I’m not sure about having input parameter(ccId). Should I read the input parameter from request object? If so can you please give me some example code.
def get_clients(request, ccId):
lstClients = Patients.objects.filter(cr=ccId)
data = serializers.serialize("json", lstClients, fields=('tel',))
return http.HttpResponse(json.dumps(data), mimetype='application/javascript')
Yes, you could read the parameters from the request object:
Maybe you will need to convert the object received to its appropriate type. Something like:
ccId = int(request.GET['ccId'].Take a look at Django documentation: https://docs.djangoproject.com/en/dev/ref/request-response/#httprequest-objects