def response(status, data):
hr = HttpResponse()
hr['Access-Control-Allow-Origin'] = '*'
hr['Content-Type'] = 'application/json'
hr['charset'] = 'utf-8'
hr.status_code = status
if type(data) == str or type(data) == unicode:
data = {
'message': data,
}
try:
hr.write(json.dumps(data))
except:
try:
hr.write(json.dumps(data, default=json_util.default))
except:
hr.status_code = 500
hr.write(json.dumps({
'error': "json serialize failed",
}))
return hr
评论列表
文章目录