我的视图有一个奇怪的问题,它以 json 格式返回响应。我的视图如下所示:
def CheckPlayer(request,client_id):
if request.method == 'GET':
try:
user = User.objects.get(id = client_id)
except:
return Error(message = "User doesnot exists.")
message = request.GET.get('message','')
if not message:
return Error(message = "Argument Missing.")
response = {}
result = MakingRequest(message)
result = json.loads(result)
if result['failure'] == '0':
response['failure'] = '0'
else:
response['failure'] = '1'
return HttpResponse(json.dumps(response), mimetype="application/javascript")
else:
return Error()
def MakingRequest(message):
values = {'message':message}
rObjects = Ram.objects.all()
temp = []
for i in rObjects:
temp.append(i.appId)
values['registration_ids'] = temp
param = json.dumps(values)
req = urllib2.Request("https://android.googleapis.com/gcm/send", param)
req.add_header( 'Content-Type' , 'application/json' )
req.add_header( 'Authorization' , 'key=7FcEMnl0FRTSBjhfjfhjfHi1Rmg04Ns' )
response = urllib2.urlopen(req)
return response.read()
我已经在我的本地服务器上对其进行了测试,它运行良好,但是如果我在我的服务器(nginx、gunicorn、django-mongoDB、mongoDB)上运行它,那么它会给我这个错误。我知道这个错误,如果视图不返回 HttpResponse从一个视图然后它 djangi 引发错误“Nonetype object has no attribute csrf_exempt'”但在我的情况下,我返回的是 json 格式的响应,但它仍然给我错误。请帮助我