快速解决方案:
在ajax请求前加上:

<script> $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }}'}, });</script>