我的视图中存在这个奇怪的问题,它以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对象没有属性csrf_exempt'”但在我的情况下我返回的响应是json格式但仍然给我错误。请帮助我
答案 0 :(得分:0)
当您返回Error()时,您没有返回HttpResponse,因此Django无法将装饰器应用于它。