Object of type type is not JSON serializable


报这个错的原因是因为json.dumps函数发现字典里面有bytes类型的数据,无法编码。解决方法:将bytes类型的数据就把它转化成str类型。

定义dates[]后return JsonResponse({'status': 200,'message':'success','data':datas})报上述错误

解决方法:return JsonResponse({'status': 200,'message':'success','data':str(datas)})

报错:CSRF token missing or incorrect.

解决方法:在view文件中加入装饰器@csrf_exemp

代码如下:

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def contact(request):
django之所以引进CSRF是为了避免Cross Site Request Forgeries攻击,而上面的解决方法恰好禁止掉这个django的功能。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM