報這個錯的原因是因為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的功能。