views.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:nanami 作者: theeluwin 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号