I am implementing GET,POST,PUT methods using django 's generic views (django.views.generic.base).
GET and POST methods are working fine. However, the PUT method is not returning any HttpResponse object, although I am getting a code 200 OK from server but no data.
I think this may be the issue related to Cross Origin Resource Sharing (CORS).
Can anyone point me to the right direction to solve this issue ?
I am using nginx + uwsgi for deplyoment.
Edit: I have enabled the nginx server to handle PUT and OPTIONS http verbs.
Here is my PUT code :
def put(self, request, *args, **kwargs):
"""
Update from the controller with info that all the commands has
been successfully executed on that controller
:param mac:
:param request:
:param args:
:param kwargs:
"""
self.true_response["mac"] = None
self.false_response["mac"] = None
if request.method == 'PUT':
if "mac" in kwargs:
mac = kwargs["mac"]
self.true_response["mac"] = mac
self.false_response["mac"] = mac
query = "SELECT COUNT(1) FROM controller WHERE \
`controller_mac` = '%s'" % mac
cursor = connections['cnms'].cursor()
cursor.execute(query)
result = cursor.fetchall()
if not result[0][0]:
return HttpResponse(json.dumps(self.false_response))
try:
query = """ UPDATE command SET command_status = 2 WHERE \
command_mac '%s'""" % mac
cursor = connections['cnms'].cursor()
cursor.execute(query)
return HttpResponse(json.dumps(self.true_response))
except Exception as error:
return HttpResponse(json.dumps(self.false_response))
else:
return HttpResponse(json.dumps({"status" : "false"}))
else:
return HttpResponse("Method is Not Supported")