在我的应用程序中,有一个端点向我发送Yaml文件的原始内容,以响应AJAX调用。我想按用户界面显示它们。控制台会抛出一个明显的错误,这是无效的JSON。我该怎么办?
更新:
filename = __file__ # Select your file here.
wrapper = FileWrapper(file(filename))
response = HttpResponse(wrapper, content_type='text/plain')
response['Content-Length'] = os.path.getsize(filename)
return response
有什么办法可以在其中形成包含文件内容的字典,然后发送响应?
从服务器上使用jsonify
原始内容,打包并将其运送到客户端。
repacked_json = json.dumps(raw_yaml_data)
json_obj = json.loads(repacked_json)
return jsonify(result = json_obj)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句