I am trying to return the the string given in URL but I am getting this error TypeError: Object of type function is not JSON serializable
don't know how to rectify this.
URL I am passing - http://127.0.0.1:8000/predict/?solute=CC(C)(C)Br&solvent=CC(C)(C)O
my views.py
file
@api_view(['GET'])
def result(request):
response = {}
solute = request.data.get('solute',None)
solvent = request.data.get('solvent',None)
results = [solute,solvent]
return Response({'result':result}, status=200)
Update: after correcting `result` to `results` it solved my problem
But it is returning an null
response in the output rather than getting CC(C)(C)Br
and CC(C)(C)O
which are my inputs through URL
You seem to be passing the function result
itself to Response
Looks like you ended up passing your view function itself as a value in the context dictionary which may not have been your intention. You may want to get things corrected this way:
@api_view(['GET'])
def result(request):
response = {}
solute = request.data.get('solute',None)
solvent = request.data.get('solvent',None)
results = [solute,solvent]
return Response({'result':results}, status=200)
Note that the name of your view function is result
and the value you intend store in the context dictionary is results
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.